Typed dataset confusion

R

Rob Richardson

Greetings!

I have a database with a table named Holdings. I has VB.Net create a .xsd
file for it so that I could use a typed dataset with it. The table has 21
rows. If I use ordinary datasets, I get a DataTable object with 21 rows.
If I use a typed dataset, I get a HoldingTable object with 0 rows. What am
I doing wrong? Here's the code:

Dim holdingsAdapter As New OleDbDataAdapter()
Dim holdingsSet As New HoldingsDataSet()
Dim holdingsTable As HoldingsDataSet.HoldingsDataTable
Dim holdingsRow As HoldingsDataSet.HoldingsRow

'Dim holdingsSet As New DataSet()
'Dim holdingsTable As DataTable
'Dim holdingsRow As DataRow

holdingsAdapter.SelectCommand = New OleDbCommand _
("SELECT * FROM Holdings", mDB)
holdingsAdapter.Fill(holdingsSet)
holdingsTable = holdingsSet.Tables(0)
MsgBox("The holdings table has " & holdingsTable.Rows.Count & " rows.")

This code is in a Try block, and no exceptions are thrown. If I used the
typed objects, I get zero rows. If I use the standard ones, I get 21 rows.

Also, I notice that my HoldingsDataSet object has a member named Holdings.
What data type is that member and what is it for?

Thanks very much!

Rob
 
J

Jeremy Cowles

You need to fill the specific table explicitly by name or the Typed table
name must match the database table name. Looks like you are doing none of
the above. Also, you are defeating the purpose of using a Typed DataSet by
using an ordnial index, just use the class as it is supposed to be:

______________________________________________

holdingsAdapter.SelectCommand = New OleDbCommand _
("SELECT * FROM Holdings", mDB)
holdingsAdapter.Fill(holdingsSet)

'// This is very bad:
'// holdingsTable = holdingsSet.Tables(0)
'// MgBox("Rows: " & holdingsTable.Rows.Count)

'// Use this instead:
Msgbox("Rows: " & holdingsSet.HoldingTable.Rows.Count)
_____________________________________________

For more info, see the section in the .NET help docs titled, "Using Typed
Datasets", or the ADO.NET group:

microsoft.public.dotnet.framework.adonet

HTH,
Jeremy
 
C

Cor

Hi Rob,

If this is all your code than you can make it much simpler
(I asume that mDB is your connection)
Dim holdingsAdapter As New OleDbDataAdapter()
Dim holdingsSet As New HoldingsDataSet()

holdingsAdapter.SelectCommand = New OleDbCommand _
("SELECT * FROM Holdings", mDB)

The adapter creates the schema and constrains from your select
holdingsAdapter.Fill(holdingsSet)
If you want you can name the table and use
holdingsAdapter.Fill(holdingsSet,"Holdings")
this is not real necessary with one table
holdingsTable = holdingsSet.Tables(0)
MsgBox("The holdings table has " & holdingsTable(0).Rows.Count & " rows.")
I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top