| | |
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 |
.net .net2008 2005 2008 access account arithmetic array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google hardcopy html images input insert intel internet mobile monitor net networking objects open output panel passingparameters pdf picturebox picturebox1 port position print printing problem save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





