have some problem with DataSets in c#, which represents structure and data of DB in sdf-file. I'm making some automatic test with DB, so I should add some rows in table, perform test and delete added rows from table.
Table schema:
Num - ID, autoincrementing, primary key
Name - string
Photo - Image (binary)
My code is:
adapter.Fill(set);
row1 = datatable.Rows.Add(null, "Name1", File.ReadAllBytes(@"Images\photo1.jpg"));
row2 = datatable.Rows.Add(null, "Name2", File.ReadAllBytes(@"Images\photo2.jpg"));
adapter.Update(set);
... perfoming test...
adapter.Fill(set);
row1.Delete();
row2.Delete();
adapter.Update(set);
But added rows are still in base. I tried use
datatable.Rows.Remove(row1);
datatable.Rows.Remove(row2);
but It cause no-such-row-exception because of wrong "Num" values in row1 and row2, which are different from actual autoincremented values in DB.
- How I can get true values of Num when I'm adding a row?
- Is there smarter solution of "add rows" -> "perform something" -> "delete added rows" problem?
Thanks in advance.