C
Chris Cummings
It's easy to do this with a data adapter.
Create stored procedures for each case: sp_insertSpice
sp_updateSpice, sp_deleteSpice
Then create SqlCommands for each that invoke the stored
procedures:
e.g. insert:
SqlCommand insertCmd = new SqlCommand
("sp_insertSpice",conn,tran);
insertCmd.CommandType = CommandType.StoredProcedure;
For each column of the table, map the column to a stored
procedure parameter:
insertCmd.Parameters.Add("@spiceName, SqlDbType.VarChar, 0,
"name")
For insert, make the primary key parameter an output
parameter if it's an autoincrement.
Then setup the data adapter to fire these commands for
each row in the table:
try
{
da.InsertCommand = <insert command>
da.UpdateCommand = <update command>
da.DeleteCommand = <delete command>
da.Update(ds.SpiceTable);
tran.Commit();
} catch (Exception e)
tran.Rollback();
}
finally
{
conn.Close();
}
Create stored procedures for each case: sp_insertSpice
sp_updateSpice, sp_deleteSpice
Then create SqlCommands for each that invoke the stored
procedures:
e.g. insert:
SqlCommand insertCmd = new SqlCommand
("sp_insertSpice",conn,tran);
insertCmd.CommandType = CommandType.StoredProcedure;
For each column of the table, map the column to a stored
procedure parameter:
insertCmd.Parameters.Add("@spiceName, SqlDbType.VarChar, 0,
"name")
For insert, make the primary key parameter an output
parameter if it's an autoincrement.
Then setup the data adapter to fire these commands for
each row in the table:
try
{
da.InsertCommand = <insert command>
da.UpdateCommand = <update command>
da.DeleteCommand = <delete command>
da.Update(ds.SpiceTable);
tran.Commit();
} catch (Exception e)
tran.Rollback();
}
finally
{
conn.Close();
}