G
Guest
I wan to execute an update command that will insert many new rows into a
database table. I loop through my dataset running the update command on each
datable. The problem is that the update commangd fails. I want to map the
parameters used in the insert command to the columns of the datatable.
Does anyone know how to do this???
The code is below:
Thanks
-Taz
private void uploadSummaryToDatabase(DataSet dst, string filePath)
{
OdbcConnection conn = new OdbcConnection();
OdbcDataAdapter adapter = new OdbcDataAdapter();
conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" +
filePath;
conn.Open();
string insComm = "INSERT INTO Summary (Sup_DUNS, Sup_Name, Sup_Street,
Sup_City, Sup_State, Sup_Country, Sup_Zip)" +
"Values (@Sup_DUNS, @Sup_Name, @Sup_Street, @Sup_City, @Sup_State,
@Sup_Country, @Sup_Zip)";
adapter.InsertCommand = new OdbcCommand(insComm, conn);
foreach (DataTable dt in dst.Tables)
{
Try
{
adapter.Update(dt);
}
catch
{
MessageBox.Show("Problem updating to the database.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
database table. I loop through my dataset running the update command on each
datable. The problem is that the update commangd fails. I want to map the
parameters used in the insert command to the columns of the datatable.
Does anyone know how to do this???
The code is below:
Thanks
-Taz
private void uploadSummaryToDatabase(DataSet dst, string filePath)
{
OdbcConnection conn = new OdbcConnection();
OdbcDataAdapter adapter = new OdbcDataAdapter();
conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" +
filePath;
conn.Open();
string insComm = "INSERT INTO Summary (Sup_DUNS, Sup_Name, Sup_Street,
Sup_City, Sup_State, Sup_Country, Sup_Zip)" +
"Values (@Sup_DUNS, @Sup_Name, @Sup_Street, @Sup_City, @Sup_State,
@Sup_Country, @Sup_Zip)";
adapter.InsertCommand = new OdbcCommand(insComm, conn);
foreach (DataTable dt in dst.Tables)
{
Try
{
adapter.Update(dt);
}
catch
{
MessageBox.Show("Problem updating to the database.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}