how to fill seleced values to combobox from sql

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 5
Reputation: mails4vijay is an unknown quantity at this point 
Solved Threads: 0
mails4vijay mails4vijay is offline Offline
Newbie Poster

how to fill seleced values to combobox from sql

 
0
  #1
Nov 24th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: reena12 is an unknown quantity at this point 
Solved Threads: 4
reena12 reena12 is offline Offline
Light Poster

Re: how to fill seleced values to combobox from sql

 
0
  #2
Nov 24th, 2008
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
Reena Mehta

Remember to click on Mark as answer on the post that helped

http://www.indianic.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: mails4vijay is an unknown quantity at this point 
Solved Threads: 0
mails4vijay mails4vijay is offline Offline
Newbie Poster

Re: how to fill seleced values to combobox from sql

 
0
  #3
Nov 24th, 2008
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()
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: reena12 is an unknown quantity at this point 
Solved Threads: 4
reena12 reena12 is offline Offline
Light Poster

Re: how to fill seleced values to combobox from sql

 
0
  #4
Nov 24th, 2008
idcombo.Items.Add(dr(0))
Reena Mehta

Remember to click on Mark as answer on the post that helped

http://www.indianic.com
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: mails4vijay is an unknown quantity at this point 
Solved Threads: 0
mails4vijay mails4vijay is offline Offline
Newbie Poster

Re: how to fill seleced values to combobox from sql

 
0
  #5
Nov 25th, 2008
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...........
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 10
Reputation: markd220 is an unknown quantity at this point 
Solved Threads: 2
markd220 markd220 is offline Offline
Newbie Poster

Re: how to fill seleced values to combobox from sql

 
0
  #6
Nov 25th, 2008
while dr.Read()
idcombo.Items.Add(dr(0))
end while
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: reena12 is an unknown quantity at this point 
Solved Threads: 4
reena12 reena12 is offline Offline
Light Poster

Re: how to fill seleced values to combobox from sql

 
0
  #7
Nov 26th, 2008
while dr.Read()
idcombo.Items.Add(dr(0))
end while
Reena Mehta

Remember to click on Mark as answer on the post that helped

http://www.indianic.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC