Question Connection / Adapter / Dataset > datagrid still shows nothing!

zabzoo

New member
Joined
Sep 10, 2008
Messages
3
Programming Experience
Beginner
VB.NET - Followed instructions to the letter but my DataGridView does not show the information in the database.

I have a DataGridView1 datagrid in Form1 and this is the code in my code page.

VB.NET:
Dim conStr As String = _ 
   "Provider=Microsoft.Jet.OLEDB.4.0;data source=H:\XXX\DATABASE\XXX.mdb"
Dim connection As OleDb.OleDbConnection = New OleDb.OleDbConnection(conStr)

'Create a data adapter
Dim sqlStr As String = "SELECT tbCompanyDetails.* FROM tbCompanyDetails"

'Instantiate a Data Adapter object
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sqlStr, connection)

connection.Open()

Dim ds As DataSet = New DataSet
da.Fill(ds, "WebsiteDetails")

DataGridView1.DataSource = ds.DefaultViewManager

Things that i have checked -
  • Imports System.Data.OleDb done at the top
  • The code appears inside Private Sub Form1_load etc...
  • The path to the database is correct
  • The select statement works fine in a query window inside access
  • I am not exactly sure what the "WebsiteDetails" part of this statement da.Fill(ds, "WebsiteDetails") does, so i made it descriptive based on my example -- i just chose website details because that is what's inside that table; not sure if was supposed to be a column name or something.
I been at it for a few days flat no -- please assist me if possible.Many thanks,
 
VB.NET:
		Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\XXX\DATABASE.mdb")
		Dim cmd As New OleDbCommand("SELECT * FROM tbCompanyDetails", cn)
		Dim da As New OleDbDataAdapter()
		Dim ds As New DataSet()

		cn.Open()
		da.SelectCommand = cmd
		da.Fill(ds, "WebsiteDetails")
		cn.Close()

		Me.DataGridView1.DataSource = ds.Tables("WebsiteDetails")
 
It works now - thank you for helping me out; it would seem i missed a few statements and more; appreciated thank you very much :D
 
only thing I would add, is how to make your life much easier.. read the DW2 link in my signature, section on Creating A Simple Data App
 
only thing I would add, is how to make your life much easier.. read the DW2 link in my signature, section on Creating A Simple Data App

Thank you; I had a quick look just now, and will study the information meticulously - appreciated!
 

Latest posts

Back
Top