Create DataSet programmatically, as object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've seen code snippets where ADO.NET datasets are created programmatically as their own class, which inherits from System.Data.DataSet. The code usually resembles, the following with tables, relationships and constraints created in the user defined class.

class DataSet : System.Data.DataSet
{
}

I've been searching for documentation on how to do this and what the requirements are for constructors and methods. Also, what are the practical applications for creating a dataset programmatically this way, beyond having full controll over the object. However, I haven't been very successful in finding information.

I would appreciate any links to reference material that anyone could send my way. Thanks in advance!
 
Hi Andre,
I think what you are thinking of is a typed data set. To create a typed data
set, you need an XML schema representing the data you want to create it
from. You can either create the XML Schema from hand, or you can get it by
dragging a SQL Server table into the XSD schema designer in Visual Studio
..NET from Server Explorer.

Once you have an XSD schema open in Visual Studio, just right click in the
designer and select the Generate DataSet menu item. Either that or use the
xsd.exe tool to create a typed data set.

What results is a class derived from DataSet that contains strongly typed
properties and nested classes for the rows and tables, and if you have
relationships in the XSD schema, those will result in data relations.

Hope that helps get you pointed in the right direction.
Brian

Andre Ranieri said:
I've seen code snippets where ADO.NET datasets are created
programmatically as their own class, which inherits from
System.Data.DataSet. The code usually resembles, the following with tables,
relationships and constraints created in the user defined class.
class DataSet : System.Data.DataSet
{
}

I've been searching for documentation on how to do this and what the
requirements are for constructors and methods. Also, what are the practical
applications for creating a dataset programmatically this way, beyond having
full controll over the object. However, I haven't been very successful in
finding information.
 
Hi Andre,

A dataset is nothing more than a collection of datatables.

A datatable can have a collection of datarows.

A datatable has datacolumns, which holds the general information about that
datacolumn (items) as type, name, etc.

a collection of datarows is a datarowcollection.

A datarow has items, the general information of those is in the datacolumns
but the item holds the actual data.

Basicly you have everything above.

I send this because when you look for those keywords in/on msdn you will see
a lot of samples

Cor



class, which inherits from System.Data.DataSet. The code usually resembles,
the following with tables, relationships and constraints created in the user
defined class.
class DataSet : System.Data.DataSet
{
}

I've been searching for documentation on how to do this and what the
requirements are for constructors and methods. Also, what are the practical
applications for creating a dataset programmatically this way, beyond having
full controll over the object. However, I haven't been very successful in
finding information.
 
I forgot to tell, this as an addition to Brian when you want to make it all
yourself.

The methode from Brian tells you is a very simple one to get your result.

Cor
 
Brian, Cor

Thank you very much for your prompt and insightful responses, that was exactly what I'm looking for. I'd been flailing about all week trying to do it by hand, it's hard to believe creating the dataset object through XMLSchema took a whole five minutes

Thanks again

Andre
 
Back
Top