472,090 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,090 software developers and data experts.

Typed dataset confusion

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
Nov 20 '05 #1
2 894
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

Nov 20 '05 #2
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
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Trond | last post: by
3 posts views Thread by Freeon | last post: by
4 posts views Thread by Ronald S. Cook | last post: by
21 posts views Thread by Peter Bradley | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.