none
How Do I Initialize an Empty Dataset? RRS feed

  • Question

  • I've always used Dataset's connected to databases by loading the data into the dataset from the database to initialize it.  In the current situation, I want to simply create an empty disconnected dataset and populate it with some data.  I have a strongly typed XSD file that defines the dataset schema.  Is there an easy way to initialize all the tables so that I have an empty data set that I can manually load data into?

    Thanks,

    Chuck
    Chuck
    Tuesday, October 13, 2009 3:30 AM

Answers

  • Thanks, I found my problem...I already had a strongly typed dataset that I had moved from another project, but none of the tables were being initialized.  It was a problem in the namespaces when I copied it over that I resolved.  To create the empty dataset all I needed to do was instantiate a new instance of it and that worked fine once I fixed the namespace problem.


    Chuck
    • Marked as answer by chuckc3 Thursday, October 15, 2009 8:55 PM
    Tuesday, October 13, 2009 12:40 PM

All replies

  • You can use DataSet.ReadXmlSchema to create all of the tables and other schema objects as specified by a DataSet XSD.

    (This will not, however, result in a strongly-typed DataSet that you can cast to a strongly-typed DataSet type.  In other words, it will be as if you created all of the DataTable, etc. objects and adding them manually to the DataSet.)
    Tuesday, October 13, 2009 3:36 AM
  • Thanks, I found my problem...I already had a strongly typed dataset that I had moved from another project, but none of the tables were being initialized.  It was a problem in the namespaces when I copied it over that I resolved.  To create the empty dataset all I needed to do was instantiate a new instance of it and that worked fine once I fixed the namespace problem.


    Chuck
    • Marked as answer by chuckc3 Thursday, October 15, 2009 8:55 PM
    Tuesday, October 13, 2009 12:40 PM