Home All Groups Group Topic Archive Search About
Author
30 Mar 2005 1:32 AM
Thomas Krause
What is the best way to add a new table to a database?

If possible I don't want to use SQL, but ADO.Net directly.

I'm a Ado-Newbie and tried the following:

dataSet.Tables.Add("xyz");
adapter.Update(dataSet);

but this does not work. I believe that Adapter.Update() only works for
Tables that already exist in the Database. But what is the alternative if I
don't like the SQL solution (CREATE TABLE ...)?

I cannot create the tables directly. I have to make that at runtime.

Thanks,
Thomas Krause

Author
30 Mar 2005 1:40 AM
Val Mazur (MVP)
Hi,

When you call dataSet.Tables.Add it adds the DataTable to the DataSet, not
to the database. Since there is no built-in .NET managed library, that
allows to create table in a database, I would suggest to use CREATE TABLE
statement or search for some third-party library that does this for you. In
a case of SQL Server you could also use COM-based SQL DMO library and in a
case of Access database use COM-based ADOX

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



Show quote
"Thomas Krause" <nospam.forum.thomas.krause.at.gmx.de@abc.de> wrote in
message news:d2cvjo$qvm$05$1@news.t-online.com...
> What is the best way to add a new table to a database?
>
> If possible I don't want to use SQL, but ADO.Net directly.
>
> I'm a Ado-Newbie and tried the following:
>
> dataSet.Tables.Add("xyz");
> adapter.Update(dataSet);
>
> but this does not work. I believe that Adapter.Update() only works for
> Tables that already exist in the Database. But what is the alternative if
> I
> don't like the SQL solution (CREATE TABLE ...)?
>
> I cannot create the tables directly. I have to make that at runtime.
>
> Thanks,
> Thomas Krause
>
>
Author
30 Mar 2005 1:01 PM
Thomas Krause
Thanks for your answers

My solution is now to make an createTable function that takes a DataTable as
an argument and adds it by building an SQL statement.

So I can now construct DataTables and then add them to the database with a
single call.

Thanks,
Thomas Krause

Show quote
"Val Mazur (MVP)" <group***@hotmail.com> wrotes:
> Hi,
>
> When you call dataSet.Tables.Add it adds the DataTable to the DataSet, not
> to the database. Since there is no built-in .NET managed library, that
> allows to create table in a database, I would suggest to use CREATE TABLE
> statement or search for some third-party library that does this for you.
In
> a case of SQL Server you could also use COM-based SQL DMO library and in a
> case of Access database use COM-based ADOX
>
> --
> Val Mazur
> Microsoft MVP
>
> http://xport.mvps.org
>
>
>
> "Thomas Krause" <nospam.forum.thomas.krause.at.gmx.de@abc.de> wrote in
> message news:d2cvjo$qvm$05$1@news.t-online.com...
> > What is the best way to add a new table to a database?
> >
> > If possible I don't want to use SQL, but ADO.Net directly.
> >
> > I'm a Ado-Newbie and tried the following:
> >
> > dataSet.Tables.Add("xyz");
> > adapter.Update(dataSet);
> >
> > but this does not work. I believe that Adapter.Update() only works for
> > Tables that already exist in the Database. But what is the alternative
if
> > I
> > don't like the SQL solution (CREATE TABLE ...)?
> >
> > I cannot create the tables directly. I have to make that at runtime.
> >
> > Thanks,
> > Thomas Krause
> >
> >
>
>
Author
30 Mar 2005 1:43 AM
Dave Fancher
You have no other option.  You need to use DDL (such as CREATE TABLE)
statements to modify the structure of a database.

Even if you were to perform this with a SqlCommand object, you'd still have
to set the CommandText property to the DDL statement.

HTH
----------------
Dave Fancher
http://davefancher.blogspot.com

Show quote
"Thomas Krause" <nospam.forum.thomas.krause.at.gmx.de@abc.de> wrote in
message news:d2cvjo$qvm$05$1@news.t-online.com...
> What is the best way to add a new table to a database?
>
> If possible I don't want to use SQL, but ADO.Net directly.
>
> I'm a Ado-Newbie and tried the following:
>
> dataSet.Tables.Add("xyz");
> adapter.Update(dataSet);
>
> but this does not work. I believe that Adapter.Update() only works for
> Tables that already exist in the Database. But what is the alternative if
> I
> don't like the SQL solution (CREATE TABLE ...)?
>
> I cannot create the tables directly. I have to make that at runtime.
>
> Thanks,
> Thomas Krause
>
>

AddThis Social Bookmark Button