MarkH12518
asked on
how to create insert command into access db
I now have a datatable that matches my access db fields and am able to fill the datatable from arrays in my c#. It is 200 X 242.
Now that I have the datatable I want to insert the rows of data, either one by one or batch into access. I attempted the OleCommandBuilder but do not have a primary key in the table. So I'm doing manually I suppose.
Can someone please indicate how I can Insert into my Access table?
Thank you
Now that I have the datatable I want to insert the rows of data, either one by one or batch into access. I attempted the OleCommandBuilder but do not have a primary key in the table. So I'm doing manually I suppose.
Can someone please indicate how I can Insert into my Access table?
Thank you
DataRow row;
int ln = dtAr.Length;
//fill rows
try
{
for (int i = 0; i < sims; i++)
{
row = prtab.NewRow();
for (int j = 0; j < ln + 2; j++)
{
if (j == 0)
{
row["tStep"] = 1;
}
else if (j == 1)
{
row["SimNum"] = i;
}
else
{
row[CrvID[j - 2].ToString() + dtAr[j - 2].ToString()] = crNs[i, j - 2];
}
}
prtab.Rows.Add(row);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Every table should have a primary key even if it is an autonumber.
INSERT INTO tablename (fieldname1, fieldname2, ...)
SELECT value1, value2, ...