In my database, I have a table with a primary key identity column, and 3 other columns as follows.
I want to manually create a DataTable and save it to my SQL Server CE database. Can anyone help me tweak my code please?
DataTable table1 = new DataTable("MyTable1");
table1.Columns.Add("LastName");
table1.Columns.Add("FirstName");
table1.Columns.Add("SortColumn");
table1.Rows.Add("Doe", "John", 1);
table1.Rows.Add("Doe", "Mary", 2);
DataSet ds = new DataSet("notCritical1");
ds.Tables.Add(table1);
using (SqlCeConnection con = new SqlCeConnection(TestClickOnceApp.classes.ClassDatabase.m_connectionString))
{
con.Open();
SqlCeDataAdapter da = new SqlCeDataAdapter("Select * from MyTable1", con);
da.Fill(ds, "MyTable1");
da.Update(ds, "MyTable1");
}
I haven’t SqlCompact to test, but I presume you could write code like this
no need to use a dataset
More details on the base class method DbDataAdapter.Update(DataTable t) can be found here