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

Recommended Answers

All 6 Replies

Hi,

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

dim objSqlCommand as new SqlCommand
dim objdr as SqlDataReader

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

while objdr.Read()
combobox1.Items.add(objdr(0))
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
con.Open()
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
dr.Read()
idcombo.Items.Add(dr("0"))
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
dr.Close()
con.Close()

idcombo.Items.Add(dr(0))

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...........

while dr.Read()
idcombo.Items.Add(dr(0))
end while

while dr.Read()
idcombo.Items.Add(dr(0))
end while

Be a part of the DaniWeb community

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