i have a combobox i want to show all the student name in it , i am using mssql database , and when we select student a textbox will show the rollno of that student , please help me

Recommended Answers

hello !
try this code , hope this will solve your prob.

Sub values()
        Dim con As New SqlConnection("connectionstring")
        con.Open()
        Dim da As New SqlDataAdapter("select name , idno from students", con)
        Dim dt As New DataTable
        da.Fill(dt)
        ComboBox1.DataSource = dt
        ComboBox1.DisplayMember = "name"
        ComboBox1.ValueMember = "idno"
    End …
Jump to Post

All 2 Replies

hello !
try this code , hope this will solve your prob.

Sub values()
        Dim con As New SqlConnection("connectionstring")
        con.Open()
        Dim da As New SqlDataAdapter("select name , idno from students", con)
        Dim dt As New DataTable
        da.Fill(dt)
        ComboBox1.DataSource = dt
        ComboBox1.DisplayMember = "name"
        ComboBox1.ValueMember = "idno"
    End Sub
'-----------------
'use this code at the selectedindex change event of your combobox
'-----------------
  TextBox1.Text = ComboBox1.SelectedValue.ToString()

Regards

thanks for this quick help , my prob is solved .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.