Can anyone give me code to populate a combobox using dataset and sqldataadapter.I want to create the dataset and dataadapter through program not through the wizard.
dim ConnectionString as string = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Employee.mdb;"
Try
Dim strSQL As String = "SELECT EmployeeID, EmployeeName " & _
"FROM Employee"
Dim conn As OleDbConnection = New OleDbConnection(ConnectionString)
' The OledbDataAdapter is used to move data between SQL Server,
' and a DataSet.
detailAdapter = New OleDbDataAdapter(strSQL, ConnectionString)
conn.Open()
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, conn)
Dim Reader As OleDbDataReader = myCommand.ExecuteReader()
combobox1.Items.Clear()
Do While Reader.Read
combobox1.Items.Add(Reader.Item("EmployeeName".ToString())
Loop
Reader.Close()
conn.Close()
myCommand.Dispose()
conn.Dispose()
Catch exc As Exception
' Unable to connect to SQL Server
MessageBox.Show("Error populating the Employee combobox."
mySQL = "SELECT au_id, au_lname, au_fname FROM authors"
'Initialize the SqlDataAdapter with the SQL and Connection String,
'And then use the SqlDataAdapter to fill the DataSet with data.
myDA = New SqlDataAdapter(mySQL, myConnection)
myDA.Fill(myDS, "authors"
BTW, I just bought a Combo Box from DinkIT (out of the Xtras.NET catalog) and it looks VERY cool. It gives the ability to have multiple columns in the drop-down. From what they tell me, you will also be able to specify column headers and styles in the next version. And it was only $49.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.