What I need to do is probably extremely simple to do but it seems I
just can't find out how.
I want to:
-Display a form with a datagridview on it.
-A button with an OpenFileDialog, which will be used to choose the .mdb
file to load.
-A combobox showing all the tables available in the .mdb
-I want the datagridview to show the table selected the in the
combobox...<---That's where I'm stuck... How the heck is it possible to
do that

DataGridView able to display different tables from .mdb?
elenaar-ms
snipexv
People here are very helpful...
I don't ask much. All I want is an indication, a snippet of code, a link or a good book suggestion to achieve this, IMHO, simple task. Well, I do think it's simple, but after Googleing like never before without any success, I'm not sure anymore if it's that easy...
neilsanner
Giri T
OK, that's for the web world; I usually do Refresh(); don't know if necessary. Glad to hear it's working.
Brian
Christineeve
Yes, I managed to do that part. Here's how:
Private Sub ButtonLoadDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLoadDB.Click
Dim Cn As ADODB.Connection, Cat As ADOX.Catalog, objTable As ADOX.Table, objKey As Key
Cn = New ADODB.Connection
Cat = New ADOX.Catalog
objTable = New ADOX.Table
' -- Open the connection
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + TextBox1.Text.Trim)
' -- Open the Catalog
Cat.ActiveConnection = Cn
' -- Fill the combobox with all the tables name
For Each objTable In Cat.Tables
If Not objTable.Name.ToLower.StartsWith("msys") Then
ComboBox_Tables.Items.Add(objTable.Name)
End If
Next
' -- clean up objects
objKey = Nothing
objTable = Nothing
Cat = Nothing
Cn.Close()
Cn = Nothing
End Sub
It's that part that I'm really not sure how to do it. Can you or anyone else post a little bit of code showing how to do this please.
Grib
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(objAdapter)
This will prevent an error from popping after we make changes to data in the dataGridView and we run this line of code, to write (update) the data in the source table:
objAdapter.Update(objTable)
Cheers!
neilsanner
Ulrich Vogl
It feels good to see it work!!! I'm so happy!
The only thing that I don't understand is this line:
datagridview1.DataBind()
If I look in the object browser, it doesn't seem to be a method of dataGridView.
And the program seems to work good without this line.
Thanks again Brian! You the man!
neilsanner
Josh Stevens - MSFT
You got the code for the first two, the last is the easiest:
objAdapter = new OledbDataAdapter("select * from " + cboTableDropDown.SelectedText, objConnection)
objTable = new DataTable
objAdapter.Fill(objTable)
datagridview1.DataSource = objTable
datagridview1.DataBind()
David Davis
Well, loading all of the database components in the code, when they select the database, you can then piece together the connection string. Then connect to the db to get the table names (don't know how to do that, did you do that successfully, and if so, how ), and then when you get that, create a sql string based on the selected value, load the dataadapter, datatable, and assign the datatable to the datasource.
Brian