convert untyped datatable/dataset into strongly typed

  • Thread starter Thread starter Somebody_Out_There
  • Start date Start date
The easiest method for existing DataSets is as follows:

Add this line after the creation of the dataset:

DataSetName.WriteXmlSchema(filePath);

Be sure to set up the file path and name the file .xsd.

Then, open the .xsd file and copy the resulting "tables" into a DataSet you
add to the project. Finally, change the line like so:

DataSet DataSetName = new DataSet();

to

StronglyTypedDataSetTypeName StronglyTypedName = new
StronglyTypedDataSetTypeName();

And, you are rolling.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
Hi,
I probably did not make myself clear the first time. I apologize.

My stored procedure would return different number of columns depending
upon the parameter passed. Also the resultset might change when users
make changes to the system's metadata. So I cannot have a static
structure to base upon.

I am looking to see if a untyped dataset could be cast or converted at
runtime to a typed dataset that I can reference later. Right now, I am
using GetSchemaTable() and looping thru the results of the stored proc
to create a Strongly typed datatable.

Is there a better way to do this?

Thanks
Kannan
 
Back
Top