Ideas: 1. Set the status identifier for each row in the DataTable, that is, the method to call the DataRow setadded (), SetModified (), Delete ()
2. Using the DataAdapter Update (DataTable) method
code example:
String connstring = "..."; Connection string
String SelectCommand = "SELECT * from item";
SqlDataAdapter da = new SqlDataAdapter (selectcommand,connstring);
SqlCommandBuilder cb = new SqlCommandBuilder (DA); Automatically generate the corresponding INSERT, UPDATE, DELETE statements
DataTable dt = new DataTable ();
Fill DT
Da. Fill (DT);
Update data and row status in DT (new, deleted, modified)
foreach (DataRow dr in Dt. Rows)
{
Code to update data (slightly)
Set line status
Dr. Setadded ();
Dr. SetModified ();
Dr. Delete ();
}
Update to Database
da. Update (DT);
Note: If the amount of data involved is large, you should consider the database-side scenarios , such as: BULK INSERT into the database, and then do batch update processing on the database side
. NET Bulk Update (INSERT, modify, delete) database