Simple Database Question: Records Not Loading

Thesolis

Member
Joined
Apr 22, 2009
Messages
16
Programming Experience
1-3
Hi all,

I have a simple test .mdb file that I want to read from.
I added it to my VB.Net 2010 project as a dataset and thought that the following code would work (as an example):

VB.NET:
Dim data As New testDataSet
Me.Text = data.Tables(0).Rows(0)(0)

Whenever I execute the code, however, I get a "There Is No Row at Position 0" error.

The records in the table show up when I go into the data sources menu and preview data, so I must be missing something obvious.

I've searched the web for a solution, but everything I've found seems to be much more complicated than what I'm trying to do, which is only to read entries from .mdb files.

Thanks for the help.
 
A DataSet is just a container. If you want data from the database then you have to query the database. The data you retrieve is then stored in the DataSet. If you have a typed DataSet then you have a DataTable for each table in the database and a TableAdapter for each of those. You create an instance of the appropriate TableAdapter and use it to Fill the appropriate DataTable in the DataSet. After editing the data, you use the same TableAdapter to Update the database with the changes from the DataTable.
 
I've searched the web for a solution, but everything I've found seems to be much more complicated than what I'm trying to do, which is only to read entries from .mdb files.

Thanks for the help.



Read the DW4 link in my signature, section "Creating a Simple Data App"
 
A DataSet is just a container. If you want data from the database then you have to query the database. The data you retrieve is then stored in the DataSet. If you have a typed DataSet then you have a DataTable for each table in the database and a TableAdapter for each of those. You create an instance of the appropriate TableAdapter and use it to Fill the appropriate DataTable in the DataSet. After editing the data, you use the same TableAdapter to Update the database with the changes from the DataTable.

I think I got it working. The missing piece was the table adapter.

Just to make sure I'm doing things right, this is the proof-of-concept code I came up with for getting information out of a dataset:
VB.NET:
Dim MyData As New testDataSet
Dim MyAdapter As New testDataSetTableAdapters.testTableAdapter
MyAdapter.Fill(MyData.Tables(0))

Me.Text = MyData.Tables(0).Rows(0)(0)
 
The point of a typed DataSet is the "typed" part. You're using it like an untyped DataSet. The typed DataSet has a property for each DataTable so you don't have to index the Tables collection. The DataTable itself is a collection so you don't need the Rows collection and the DataRow has a property for each field so you don't need to index the row either:
Dim data As New SomeDataSet
Dim adapter As New SomeDataSetTableAdapters.SomeTableAdapter

adapter.Fill(data.SomeTable)

Me.Text = data.SomeTable(0).SomeColumn
 
Back
Top