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

Discussion in 'Microsoft ADO .NET' started by nicolas.neuilly@gmail.com, Dec 14, 2005.

  1. Guest

    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
     
    , Dec 14, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rajesh Madhra

    SQLHelper Class problem

    Rajesh Madhra, Jul 16, 2003, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    721
    Rajesh Madhra
    Jul 16, 2003
  2. Jeff Petter

    Problem DataBinding DropDownList Control

    Jeff Petter, Oct 3, 2003, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    246
    Jeff Petter
    Oct 3, 2003
  3. Jan Nielsen
    Replies:
    0
    Views:
    226
    Jan Nielsen
    Dec 7, 2004
  4. David Browne

    Re: SQLHelper.ExecuteReader - Connection Close

    David Browne, Apr 13, 2005, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    2,424
    Teemu Keiski
    Apr 15, 2005
  5. Replies:
    0
    Views:
    890
Loading...

Share This Page