I've configured my connection. My adapter pulls two columns from a SQL table;VENDORID and VENDNAME. I binded it to a dropdownlist, so it will show the contents of the VENDORID column in the dropdownlist on page load. Now I need to change the text of a textbox based on the selected item in the dropdown list. So whichever VENDORID is selected in the drop-down list, i need the text to change to the VENDORNAME that is on the same row in sql. Can I use the same adapter? I'm not sure how to do this.

I tried using a sqlcommand that runs a query select VENDNAME from PM00200 where VENDID='value thats selected' and storing it in a variable. But it gives me problems with my string. Here's the code:

Private Sub ddlVendorID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlVendorID.SelectedIndexChanged

Dim conn As New SqlClient.SqlConnection()
Dim comm As New SqlClient.SqlCommand()
Dim vname As String

With conn
.ConnectionString = "server=HAL/SBMTWO;uid=sa;password=sapass;initial catalog=SBM01"
End With

With comm
.CommandType = CommandType.Text
.CommandText = "select vendname from pm00200 where VENDORID='" + ddlVendorID.SelectedItem.Value.ToString + "'"
End With
conn.Open()
comm.ExecuteReader()
vname = comm.ToString

txtVendorName.Text = vname.ToString

End Sub


I don't get any errors, but the values don't carry to the textbox on selectedindexchange.

Anyway around this?

Thanks!