bramsquad
asked on
trouble with datagrid population
im trying to populate a datagrid from an oledb connection (ms access db) programmatically. ive found this solution in C#, and tried to convert it to vb, and alas, it doesnt work.
http://www.c-sharpcorner.com/database/data_view_1.asp
here is what i think is the equivelent code in vb.
Dim connectionstring As String = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" + tbl + ";Persist Security Info=False"
Dim conn As New OleDb.OleDbConnection(conn ectionstri ng)
Dim adapter As New OleDb.OleDbDataAdapter("se lect * from tblFinal", conn)
'create a new dataset
Dim ds As New DataSet
'fill dataset
adapter.Fill(ds, "tblFinal")
'attatch dataset to datagrid
DataGrid1.DataSource = ds.DefaultViewManager
thanks in advance!
~bramsquad
http://www.c-sharpcorner.com/database/data_view_1.asp
here is what i think is the equivelent code in vb.
Dim connectionstring As String = "Provider=Microsoft.Jet.OL
Dim conn As New OleDb.OleDbConnection(conn
Dim adapter As New OleDb.OleDbDataAdapter("se
'create a new dataset
Dim ds As New DataSet
'fill dataset
adapter.Fill(ds, "tblFinal")
'attatch dataset to datagrid
DataGrid1.DataSource = ds.DefaultViewManager
thanks in advance!
~bramsquad
ASKER
databind() is not an option, there is a databindings() but thats about it
DataGrid1.DataBind() is needed only for web applications (not for winforms)
Instead of this line
DataGrid1.DataSource = ds.DefaultViewManager
use
DataGrid1.DataSource = ds ' if you have only 1 datatable in the dtaset
or
DataGrid1.DataSource = ds.Tables("YourTableName')
Instead of this line
DataGrid1.DataSource = ds.DefaultViewManager
use
DataGrid1.DataSource = ds ' if you have only 1 datatable in the dtaset
or
DataGrid1.DataSource = ds.Tables("YourTableName')
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you have to add DataGrid1.DataBind() and the end
Regards,
B..M