943,589 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4408
  • VB.NET RSS
Nov 24th, 2008
0

how to fill seleced values to combobox from sql

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mails4vijay is offline Offline
5 posts
since Nov 2008
Nov 24th, 2008
0

Re: how to fill seleced values to combobox from sql

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
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Nov 24th, 2008
0

Re: how to fill seleced values to combobox from sql

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()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mails4vijay is offline Offline
5 posts
since Nov 2008
Nov 24th, 2008
0

Re: how to fill seleced values to combobox from sql

idcombo.Items.Add(dr(0))
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Nov 25th, 2008
0

Re: how to fill seleced values to combobox from sql

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...........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mails4vijay is offline Offline
5 posts
since Nov 2008
Nov 25th, 2008
0

Re: how to fill seleced values to combobox from sql

while dr.Read()
idcombo.Items.Add(dr(0))
end while
Reputation Points: 14
Solved Threads: 2
Newbie Poster
markd220 is offline Offline
10 posts
since Nov 2008
Nov 26th, 2008
0

Re: how to fill seleced values to combobox from sql

while dr.Read()
idcombo.Items.Add(dr(0))
end while
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Into two separate tables from one form?
Next Thread in VB.NET Forum Timeline: Read text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC