XSD From SQL Table

C

C Addison Ritchie

The way I go about quickly building schemas is to let the framework do the
work. What I do is setup a DataAdapter as if I was going to populate a
DataSet with data. But instead of calling .Fill() I call .FillSchema().
Then when the DataSet is just the way I like it I write it to a file using
DataSet.WriteXmlSchema().

For example:
// code to setup connection, etc.
DataSet ds = new DataSet("mySchema"); // make sure you give it a good
proper name
SqlDataAdapter da = new SqlDataAdapter("select * from orders", conn);

da.FillSchema(ds, System.Data.SchemaType.Source, "orders"); // again
give a good proper name here

// continue building your schema adding more tables and relationships

// write the schema to a file
ds.WriteXmlSchema("MySchema.schema");

HTH,

C Addison Ritchie, MCSD
Ritch Consulting, Inc.
 

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