Creating an STD


In this blog entry, we will talk about STDs (strongly typed datasets, not sexually transmitted diseases). I am going to show you how to switch from DataSets to STDs in just a few steps. It is not a drag and drop demo.
 
First, you have some code like this (this uses sp_help to get database info):
 
SqlConnection conn = new SqlConnection(_connString);
SqlCommand cmd = new SqlCommand("sp_help", conn);
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet("DatabaseInfo");
SqlDataAdapter da = new SqlDataAdapter(cmd);

try
{
   conn.Open();
   da.Fill(ds);
}
catch (System.Exception ex)
{
   //You would normally have something here
}
finally
{
   conn.Dispose();
}

Now add one line after the finally:

ds.WriteXmlSchema("C:\DatabaseInfo.xsd");

You now add a DataSet to your project:
Add Item
Add DataSet
 
 Now, open the XML Schema you saved. Select all and then paste into your new Dataset in your project. Then, change the following line of code from
 
DataSet ds = new DataSet("DatabaseInfo");
 
to
 
DataBaseInfoDS ds = new DatabaseInfoDS();
You now have switch to an STD without much effort.
 
 
 

One Response to Creating an STD

  1. Unknown says:

    Great article.   But what happens if you publish the app via One-Click Deployment?  Does this STD get embeded into the app or does it have to be read from the disk

Leave a comment