Is there an easy and direct way of creating an SQLServer table using the .Net dataset

F

Frankz

Hi, I am new to this group so forgive me if this question sounds too
newbie. :)

I am writing a C# program. One of its functionalities is to use a .Net
dataset to create and populate a table in the SQLServer database. I
suppose I can

1) iterate through the column names of the .Net dataset
to generate an SQL "CREATE TABLE" statement to
create the table;
2) iterate through each rows in the dataset to generate
a bunch of SQL "INSERT" statements to insert the
data to the table created.

I just wonder if there is an easier and more straight forward way?
Something like a direct mapping?

Thanks in advance.

Frank
 
D

Dave Sexton

Hi Frank,
I am writing a C# program. One of its functionalities is to use a .Net
dataset to create and populate a table in the SQLServer database. I
suppose I can

1) iterate through the column names of the .Net dataset
to generate an SQL "CREATE TABLE" statement to
create the table;

You should look into using SMO:

"SQL Server Management Objects"
http://msdn2.microsoft.com/en-us/library/ms162169.aspx

or DMO for legacy versions of Sql Server (pre-2005):

"SQL Distributed Management Objects"
http://msdn2.microsoft.com/en-us/library/ms131540.aspx
2) iterate through each rows in the dataset to generate
a bunch of SQL "INSERT" statements to insert the
data to the table created.

Check out the SqlDataAdapter class:

"SqlDataAdapter Class"
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

<snip>
 

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