| | |
how to fill seleced values to combobox from sql
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 32
Reputation:
Solved Threads: 4
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
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
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
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()
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()
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Into two separate tables from one form?
- Next Thread: Read text file
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





