We are working on ADO today. NET adapter automatically triggers the database update function for data, and finds a very strange problem. Originally, data operations were performed by their own code to complete the update, and this method was never involved, so it was a problem.
1 SQLiteDataAdapter dataAdpater = new SQLiteDataAdapter("Select cid,sd from VC", conn);
2 dataAdpater.DeleteCommand = new SQLiteCommand("delete From VC Where cid = @cid", conn);
3 dataAdpater.DeleteCommand.Parameters.Add("@cid", DbType.Int32, 4, "cid");
4 dataAdpater.DeleteCommand.Parameters["@cid"].SourceVersion = DataRowVersion.Original;
5
6 DataTable categoryTable = new DataTable();
7 dataAdpater.Fill(categoryTable);
8 categoryTable.PrimaryKey = new DataColumn[]{categoryTable.Columns["cid"]};
9
10 DataRow dr = categoryTable.Rows.Find(213213);
11 categoryTable.Rows.Remove(dr);
12 dataAdpater.Update(categoryTable);
Run the above Code and find that the physical database has not been deleted. It is strange that the 213213 record corresponding to the last debug statement does not exist. Why has the database not been deleted, later, I found that DataRow has a Delete function in MSDN. I will try it immediately and Delete it successfully.
1 DataRow dr = categoryTable.Rows.Find(213213);
2 dr.Delete();
3 dataAdpater.Update(categoryTable);
The query on MSDN is explained as follows:
DataTable. Rows. Remove (row): Calling Remove is the same as calling Delete and then calling AcceptChanges.
DataTable. Rows [I]. Delete (): A deleted row can be undeleted by invoking RejectChanges.
In this way, it is clear that all record sets in the DataTable have their own modification flag, proving that each record is "add", "delete", "modify", and all adpater. during the Update process, different cmd commands will be called to synchronize the final data. Ten years ago, my colleague used XML to return the dataset. This method was used for local offline editing and then submitted to the database at one time, ha, my colleague is indeed awesome!