How to create a table from an XSD?

  • Thread starter Thread starter Sheila Jones
  • Start date Start date
S

Sheila Jones

Hello,



I have a (hopefully) simple question, but can't seem to find the answer. It
's easy to retrieve the schema of a database table using ADO.Net, but what
about going the 'other way round', i.e. using a schema to create a table?



I could write my own code to parse the schema and build the appropriate
CREATE TABLE command, but is this re-inventing the wheel? Some pointers to
documentation/sample code etc. would be appreciated. Thanks.



(For reference, I am using an Access database with the Jet 4 provider.)
 
Hi Sheila,

Sheila Jones said:
Hello,



I have a (hopefully) simple question, but can't seem to find the answer. It
's easy to retrieve the schema of a database table using ADO.Net, but what
about going the 'other way round', i.e. using a schema to create a table?

No support there.
I could write my own code to parse the schema and build the appropriate
CREATE TABLE command, but is this re-inventing the wheel? Some pointers to
documentation/sample code etc. would be appreciated. Thanks.

Yes, do that.
As another solution - you might use Adox.
 
Hi Miha,

Thank you for your reply. I am slightly surprised there is no built in
support for creating tables, but it does explain why I didn't find anything
in the documentation :).

Certainly, Adox would be another approach, but a) it's not very ".Net" and
b) it would probably require more code than just building a Sql string.

Thanks again!
 
Hi Sheila,

This I did post yesterday for David in this newsgroup on the question how to
make a database table from a dataset, first I said it could not, but I
think it can, but I never tried.

However I think it is not to difficult to loop through the datacolumns and
than make this kind of create strings from the information in the
datacolumns.

A very simple table (watch typos because I did change it here from VB in C#)
\\\\
OleDb.OledbCommand cmd = new OleDb.OleDbCommand( "CREATE TABLE tbl1 (a int
NOT NULL,b Char(20) CONSTRAINT [pk_a] PRIMARY KEY (a))", conn);
cmd.ExecuteNonQuery();
///
When it is SQL change OleDB.Oledb for SQLClient.SQL

You can try.

Cor
 
Hi Cor,

Yes, I did see your post. But I was wondering if ADO.Net could build the
CREATE TABLE commmand automatically, similar to how it can build Insert,
Update and Delete commands. It seems not, so I will have to examine the
schema and build the command myself along the lines you suggest.

Thanks.
 
Back
Top