I'm doing a project involving VB.Net 2008 and SQL.
I'm trying to make a combobox display whats in the sql database that is connected on the left hand side.
how do i do this?
Sam
I'm doing a project involving VB.Net 2008 and SQL.
I'm trying to make a combobox display whats in the sql database that is connected on the left hand side.
how do i do this?
Sam
Dim ds as New DataSet
Dim cmd As New SqlCommand(your query, connection)
Dim da As New DataAdapter(cmd)
da.fill(ds)
combobox.datasource = ds
Hope, the above code can help you.
Dim ds as New DataSet Dim cmd As New SqlCommand(your query, connection) Dim da As New DataAdapter(cmd) da.fill(ds) combobox.datasource = ds
Hope, the above code can help you.
Thanks what do I type for the connection and datasource
Give the connection string in the place of connection or else see the following code part
Dim connection As New SqlConnection="Datasource=<your servername>; Initial Catalog=<your DB Name>;user id=<uid>;password=<pwd>"
It looks like you are reading this from a dataset, not a database? If so, go into the dataset designer and click to highlight one of the table adapters. Then in the Properties pane, click the little plus symbol (+) to expand the field "Connection" and the connection string will be in there.
An easy way to populate a combobox with data from a SQL database, using a dataset would be to create a query in the table adapter of the desired table. You would have to set up this query (using SQL) to get the data that you want. Then set the data source of the combo box to that table.
I realize that reading this could be confusing. I had done something like this. I had a table in my dataset that populated fully from a SQL database, and then I built queries to help populate only one column of data into the comboboxes. Maybe this will help:
Dim tblparts As DataSet1.docHeaderDataTable
tblparts = Me.DocHeaderTableAdapter.GetPartByModel(Convert.ToString(cmbModel.SelectedValue))
Me.cmbPart.DataSource = tblparts
Me.cmbPart.DisplayMember = "Part"
Me.cmbPart.ValueMember = "Part"
Maybe this is a start?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.