how to insert datarow into Access table?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

Assuming I have a datarow (or a datarow collection), would it possible to
create an Access table and dump the datarow(s) into that Access table? I
wouldn't even need to create the fields in the Access table since the
datarow contains the exact table schema. I'm currently taking each datarow
and creating an Insert statement that i then run against Access.
I posted this question earlier and someone suggested "configure an
OleDbDataAdapter with a proper connection and insert command, and then just
invoke Update on the pre-configured data adapter?". Then I asked him what my
Insert statement would look like (since I only have a datarow), but he
hasn't replied yet.
So assuming I have a datatable with all the rowsI need to insert, what would
my next step be?

Thanks.
 
Hi,

One way you can accomplish this is to loop through your collection. On the
first iteration use a SELECT INTO statement for the first row. This will
create the table and insert the values at the same time. On the next
iteration you can now use the normal INSERT INTO statement for the rest of
the rows that you have to insert. I have posted some sample syntax of the
sql statements for you below.

I hope this helps.
 
Back
Top