Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling a combo box with the results from a DataSet?

Status
Not open for further replies.

dollarbillg

Programmer
Dec 3, 2002
12
0
0
US
I am trying to fill a combo box. I created a DataGrid and everything works fine with that. However, I am trying to fill a combo box with the same data. (just trying to experiment). In VB 6.0 I could loop thru a record set and fill the combo box that way. Is there a similar method in .NET. Actually, I try anything at this time.

MY CODE...
Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
Dim sConnectionString As String = _
"initial catalog=Northwind;integrated security=SSPI;persist security info=False;workstation id=GB-NTWS-282;packet size=4096"

Dim cnNorthwind As New SqlConnection(sConnectionString)
Dim cmdOrders As New SqlCommand("OrderInfo", cnNorthwind)
cmdOrders.CommandType = CommandType.StoredProcedure

cmdOrders.Parameters.Add(New SqlParameter("@CustomerID", SqlDbType.VarChar, 5))
cmdOrders.Parameters("@CustomerID").Value = txtOrder.Text()

Dim daGetOrders As New SqlDataAdapter(cmdOrders)
Dim dsOrders As New DataSet()
daGetOrders.Fill(dsOrders, "Orders")
DataGrid1.DataSource = dsOrders.Tables("Orders")

ComboBox1.Items.Add = dsOrders.Tables("Orders")
End Sub

ANY AND ALL SUGGESTIONS ARE HELPFUL.

Z
 
you can do it the same way.

ComboBox1.datasource = dsOrders.Tables("Orders").DefaultView
combobox1.displaymember = "FieldNameyouwantDisplayed"
combobox1.valuemember ="FieldNameYouWantAsValue"

The valuemember is optional. It will default to whatever you set as the displaymember.
 
dollarbillg:
Try something like this:

cmboReportList.DataSource() = yourdataset
For j = 0 To dataDude.Tables(0).Rows.Count - 1
cmboReportList.Items.Add
(dataDude.Tables(0).Rows(j).Item(0).ToString)
Next

That should do it.
 
dollarbillg:
Try something like this:

cmboBox.DataSource() = yourdataset
For j = 0 To yourdataset.Tables(0).Rows.Count - 1
cmboBox.Items.Add
(yourdataset.Tables(0).Rows(j).Item(0).ToString)
Next

That should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top