Create a typed dataset

V

Vayse

I find the typed datasets created by the Data Sources Wizard very useful.
However, thats only for Forms.

How would I create a typed dataset through code?
Thanks
Vayse
 
C

Cor Ligthert [MVP]

Vayse,

Just like this

Public Class myDataSet
Inherits DataSet
' and than fill all methods and properties with you own code and business
rules.

I hope this helps,

Cor
 
M

Miha Markic [MVP C#]

See the code behind the xsd dataset files and you'll see what code wizard
generates.
 
W

W.G. Ryan - MVP

Vayse - in addition to what the others have mentioned, you can just use Add
New Item and then select Data Set (when you used the Wizard, I don't think
this is what you were referring to - if it was, forgive my redundancy.).
This isn't the wizard and you can add it as a class to a library, console
application or whatever else. As Miha mentioned, you may want to use Show
All Items to see the specific class file so you can edit it (one problem
that I've run into is needing to change the namespace after I've created the
data set, and the only way I know to do that simply is to edit the code
file. Coding a typed dataset by hand though, purely through code is a bit
tedious, so you may want to use Code Smith or create a specific template and
then just modify it, writing the whole thing from scratch is going to be a
bit of a pain and probably a bit error prone.
 
V

Vayse

Thanks.
By Wizard, I meant select Data menu, then Add New Data Source. This starts
the Data Source Configuration Wizard.

The method you are talking about, is that select Project, then Add New Item?
If so, I don't see Data Set in the items I can add. Sorry if I'm on the
wrong track.

If I choose Add Existing Item, I can select a Dataset that was already
created. (For examples AssetsDataSet.xsd)
If this is the easier way, thats fine. I can create the dataset in another
project than add it.

Can you explain further about the namespace issue.
After adding the exising dataset to a new blank project, and doing Show All,
I can see AssetsDataSet.xsd, which has 4 files off it:
AssetsDataSet.designer.vb
AssetDataSet.xsc
AssetDataSet.xss
AssetsDataSet1.designer.vb

In AssetsDataSet1.designer.vb, I have errors. Such as

Partial Public Class AssetsDataSet
Inherits System.Data.DataSet

Private tableAssets As AssetsDataTable ' Error - already declared in
this class
Private tableCatgs As CatgsDataTable ' Error - already
declared in this class
Private tableCostCentres As CostCentresDataTable ' Error - already
declared in this class
etc.

The two designers are obviously conflicting - what must I do to solve this?

thanks
Vayse
 
K

Kevin Yu [MSFT]

Hi Vayse,

Are you using VS.NET 2005? If so, I suggest you install the latest Release
Candidate. You will see DataSet in the Add New Item list.

You're getting the error because there is something wrong with your DataSet
schema. You can try to create the DataSet, drag and drop tables into the
designer and generate new classes.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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