Combobox and Textbox problem

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Experts

I use following codes to diplay data in combobox

str = "SELECT sno,name,city FROM employees"
cmd = New SqlClient.SqlCommand(str, con)
da = New SqlClient.SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)

With ComboBox1
.DataSource = dt
.DisplayMember = "name"
.ValueMember = "sno"
.SelectedIndex = 0
End With

Table has three fields as sno,name,city
Combobox displays name column
and data in table is as

sno--name-----city
1-------a------london
2-------b------moscow
3-------c-------tehran

Supose combobox text=a then
I want to display following corresponding data in textbox1 and textbox2

textbox1.text=1
textbox2.text=london

(the first row of data)

please help
 
Try this...

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
textbox1.Text = DirectCast(ComboBox1.SelectedItem, DataRowView)(0).ToString()

Dim cmd As New SqlCommand("select city from employees where sno=" & textbox1.Text & "", con)
textbox2.Text = cmd.ExecuteScalar().ToString()
End Sub
 
Back
Top