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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Rajesh Madhra

    SQLHelper Class problem

    Rajesh Madhra, Jul 16, 2003, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    904
    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:
    320
    Jeff Petter
    Oct 3, 2003
  3. a
    Replies:
    1
    Views:
    586
    Kevin Yu [MSFT]
    Jul 16, 2004
  4. Jan Nielsen
    Replies:
    0
    Views:
    270
    Jan Nielsen
    Dec 7, 2004
  5. David Browne

    Re: SQLHelper.ExecuteReader - Connection Close

    David Browne, Apr 13, 2005, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    3,073
    Teemu Keiski
    Apr 15, 2005
  6. E. Rodriguez

    Help With SqlTransactions and the SqlHelper object

    E. Rodriguez, May 19, 2005, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    1,025
    Rogas69
    May 20, 2005
  7. Paul Aspinall

    Databinding DropDownList and Label

    Paul Aspinall, Feb 6, 2006, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    264
    Guest
    Feb 6, 2006
  8. Replies:
    0
    Views:
    1,100
Loading...