i have customer details in my sql database. then i have a textbox, combobox & button. if i type customer name in a textbox i should get his id in combobox. if there is more than one customer with same name that id also should fill in combobox. i need a code for this in vb.net windows application


dim con as new DqlConnection
con = new Sqlconnection(constr)

dim objSqlCommand as new SqlCommand
dim objdr as SqlDataReader

objSqlCommand = new SqlCommand ("YOUR QUERY")
objdr = objSqlCommand.ExecuteReader()

while objdr.Read()
end while

thanks for reply but i got error indexoutofrange exception was unhandled..

here is my code....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As New SqlCommand("select cus_id,cus_type from customer where cus_name= @cus_name ", con)
With cmd.Parameters.Add(New SqlParameter("@cus_name", Me.nametxt.Text))
End With
dr = cmd.ExecuteReader()
If (dr.HasRows) Then
custype = dr("cus_type").ToString()
If custype = "A" Then
tenlt.Visible = True
tenlt.Checked = True
ElseIf custype = "B" Then
twentylt.Visible = True
twentylt.Checked = True
ElseIf custype = "C" Then
twentyfivelt.Visible = True
twentyfivelt.Checked = True
End If
End If

thanks for reply.
But this time i getting only one id. i have three customer with same name. i need to add all three id.
please help me...........

This article has been dead for over six months. Start a new discussion instead.