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.)

Re: How to create a table from an XSD? by Miha

Miha
Fri Feb 06 04:43:57 CST 2004

Hi Sheila,

"Sheila Jones" <sheilavjones@btopenworld.com> wrote in message
news:%23hQVRhJ7DHA.2056@TK2MSFTNGP10.phx.gbl...
> 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.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com



Re: How to create a table from an XSD? by Sheila

Sheila
Fri Feb 06 05:00:20 CST 2004

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!


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:uYkFf4J7DHA.452@TK2MSFTNGP11.phx.gbl...
> Hi Sheila,
>
> "Sheila Jones" <sheilavjones@btopenworld.com> wrote in message
> news:%23hQVRhJ7DHA.2056@TK2MSFTNGP10.phx.gbl...
> > 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.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & software development
> miha at rthand com
> www.rthand.com
>
>



Re: How to create a table from an XSD? by Cor

Cor
Fri Feb 06 06:38:57 CST 2004

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




Re: How to create a table from an XSD? by Sheila

Sheila
Fri Feb 06 08:52:15 CST 2004

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.


"Cor" <non@non.com> wrote in message
news:OBx$B6K7DHA.3288@TK2MSFTNGP11.phx.gbl...
> 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
>
>
>