Hello All,
I have an application where I manually build two DataTables (i.e., I don't
query a database table to populate the DataTables). I have to do this
manual creation of the DataTables. These DataTables have the same structure
as their associated database tables.

Once I have the manual DataTables created with all the required data, I'd
like to then insert the entire DataTable into its associated database table,
without having to loop through each record of the DataTable and perform an
insert for each row. Does that make sense?

Would anyone know if it's possible to take a manually built DataTable and
insert all the data from it into a database table in one swoop? And, if so,
how?

Thanks.

Re: Insert into Table from Manually Built DataTable by Miha

Miha
Thu Aug 04 03:00:45 CDT 2005

Hi,

errr, DataTables are always built manually, well, sort of. DataAdapter can
build one for you but such DataTable is not different from one built
manually.
So, you would need a properly configured dataadapter for storing data from a
DataTable to database and if we are talking .net 1.1 and sql server, there
is batch update support. The batch update support for sql server is comming
with .net 2.0.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"og" <og@nospam.com> wrote in message
news:Of4FypGmFHA.764@TK2MSFTNGP14.phx.gbl...
> Hello All,
> I have an application where I manually build two DataTables (i.e., I don't
> query a database table to populate the DataTables). I have to do this
> manual creation of the DataTables. These DataTables have the same
> structure
> as their associated database tables.
>
> Once I have the manual DataTables created with all the required data, I'd
> like to then insert the entire DataTable into its associated database
> table,
> without having to loop through each record of the DataTable and perform an
> insert for each row. Does that make sense?
>
> Would anyone know if it's possible to take a manually built DataTable and
> insert all the data from it into a database table in one swoop? And, if
> so,
> how?
>
> Thanks.
>
>
>
>



Re: Insert into Table from Manually Built DataTable by og

og
Thu Aug 04 09:48:05 CDT 2005

Hello, and thanks for the reply.

When a say built manually, what I'm referring to is something like:

DataTable dt = new DataTable;
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
DataRow dr = dt.NewRow();
dr["col1"] = "row1";
dr["col2"] = "row2";
dr["col3"] = "row3";

which I'm sure you already know. But, the point is that I'm not using a
SqlDataAdapter to build my DataTable.

Also, I'm using VS2005 (.NET 2.0) and SQL Server 2005--all beta versions, of
course.

So, is there some sort of batch method to put the whole manually built
DataTable into the database table in one pass? Or, am I forced to iterate
thru each row in the manually built DataTable and perform a separate insert
statement for each row?

Thanks for the help.




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OikUhqMmFHA.2080@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> errr, DataTables are always built manually, well, sort of. DataAdapter can
> build one for you but such DataTable is not different from one built
> manually.
> So, you would need a properly configured dataadapter for storing data from
a
> DataTable to database and if we are talking .net 1.1 and sql server, there
> is batch update support. The batch update support for sql server is
comming
> with .net 2.0.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "og" <og@nospam.com> wrote in message
> news:Of4FypGmFHA.764@TK2MSFTNGP14.phx.gbl...
> > Hello All,
> > I have an application where I manually build two DataTables (i.e., I
don't
> > query a database table to populate the DataTables). I have to do this
> > manual creation of the DataTables. These DataTables have the same
> > structure
> > as their associated database tables.
> >
> > Once I have the manual DataTables created with all the required data,
I'd
> > like to then insert the entire DataTable into its associated database
> > table,
> > without having to loop through each record of the DataTable and perform
an
> > insert for each row. Does that make sense?
> >
> > Would anyone know if it's possible to take a manually built DataTable
and
> > insert all the data from it into a database table in one swoop? And, if
> > so,
> > how?
> >
> > Thanks.
> >
> >
> >
> >
>
>



Re: Insert into Table from Manually Built DataTable by Miha

Miha
Thu Aug 04 12:35:51 CDT 2005

Hi,

You should use SqlDataAdapter to store the records - it is exactly what are
you looking for.
It doesn't matter how the DataTable was built.
Check out the help files about SqlDataAdapter class.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info


"og" <og@nospam.com> wrote in message
news:eNBTgNQmFHA.2656@TK2MSFTNGP14.phx.gbl...
> Hello, and thanks for the reply.
>
> When a say built manually, what I'm referring to is something like:
>
> DataTable dt = new DataTable;
> dt.Columns.Add("col1");
> dt.Columns.Add("col2");
> dt.Columns.Add("col3");
> DataRow dr = dt.NewRow();
> dr["col1"] = "row1";
> dr["col2"] = "row2";
> dr["col3"] = "row3";
>
> which I'm sure you already know. But, the point is that I'm not using a
> SqlDataAdapter to build my DataTable.
>
> Also, I'm using VS2005 (.NET 2.0) and SQL Server 2005--all beta versions,
> of
> course.
>
> So, is there some sort of batch method to put the whole manually built
> DataTable into the database table in one pass? Or, am I forced to iterate
> thru each row in the manually built DataTable and perform a separate
> insert
> statement for each row?
>
> Thanks for the help.
>
>
>
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:OikUhqMmFHA.2080@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> errr, DataTables are always built manually, well, sort of. DataAdapter
>> can
>> build one for you but such DataTable is not different from one built
>> manually.
>> So, you would need a properly configured dataadapter for storing data
>> from
> a
>> DataTable to database and if we are talking .net 1.1 and sql server,
>> there
>> is batch update support. The batch update support for sql server is
> comming
>> with .net 2.0.
>>
>> --
>> Miha Markic [MVP C#] - RightHand .NET consulting & development
>> www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>> SLODUG - Slovene Developer Users Group www.codezone-si.info
>>
>> "og" <og@nospam.com> wrote in message
>> news:Of4FypGmFHA.764@TK2MSFTNGP14.phx.gbl...
>> > Hello All,
>> > I have an application where I manually build two DataTables (i.e., I
> don't
>> > query a database table to populate the DataTables). I have to do this
>> > manual creation of the DataTables. These DataTables have the same
>> > structure
>> > as their associated database tables.
>> >
>> > Once I have the manual DataTables created with all the required data,
> I'd
>> > like to then insert the entire DataTable into its associated database
>> > table,
>> > without having to loop through each record of the DataTable and perform
> an
>> > insert for each row. Does that make sense?
>> >
>> > Would anyone know if it's possible to take a manually built DataTable
> and
>> > insert all the data from it into a database table in one swoop? And,
>> > if
>> > so,
>> > how?
>> >
>> > Thanks.
>> >
>> >
>> >
>> >
>>
>>
>
>