PC Review


Reply
Thread Tools Rate Thread

Databinding problem with sqlhelper.executereader and a dropdownlist in VB.NET

 
 
nicolas.neuilly@gmail.com
Guest
Posts: n/a
 
      14th Dec 2005
Basically, I have a DropDownList control on a page that inputs a string
into a database. The user can later go back to the same page in
"update" mode to make further changes. So what I need to do is pull the
value back out of the database and pass it back to the control so that
value is pre-selected in the dropdown list. It works out except when
the field is a foreign key of another table.

Here is the code. It works out for the textbox and the first ddl, but
not for the second dll as field3 is in table 2:
Sub Bind()
Dim dr As SqlDataReader
Dim sql As String = "Select * from TABLE1 T1,TABLE2 T2 where T1.KEY2 =
T2.KEY2 AND KEY1 = " & ItemID
dr = SQLHelper.ExecuteReader(ConnectionString,
System.Data.CommandType.Text, sql)
If dr.HasRows Then
dr.Read()
TextBox1.Text = dr("FIELD1").ToString
DDL1.SelectedIndex =
DDL1.Items.IndexOf(DDL1.Items.FindByText(dr("FIELD2").ToString))
DDL2.SelectedIndex =
DDL2.Items.IndexOf(DDL2.Items.FindByText(dr("FIELD3").ToString))
DataBind()
end if
dr.Close
End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databinding problem in dropdownlist jonny Microsoft VB .NET 0 28th Sep 2009 10:01 PM
dropdownlist databinding problem E. Kwong Microsoft Dot NET 0 26th Nov 2008 02:19 AM
SQLHelper ExecuteReader not closing connections sljones@dodo.com.au Microsoft ADO .NET 0 21st May 2007 05:56 AM
problem databinding a dropdownlist within a repeater Milsnips Microsoft ASP .NET 1 3rd Oct 2006 01:26 PM
Re: SQLHelper.ExecuteReader - Connection Close David Browne Microsoft ADO .NET 3 15th Apr 2005 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.