SQL Server CE插入/更新多行
本文关键字:更新 插入 Server CE SQL | 更新日期: 2023-09-27 18:22:02
我正试图在一个事务中插入大量的多行。但是SQL Server数据库并没有在更新中得到反映。下面是我的代码片段。我做错了什么?
private void Form1_Load(object sender, EventArgs e)
{
string conString = Properties.Settings.Default.Database1ConnectionString;
Database1DataSet.Table1DataTable dt = new Database1DataSet.Table1DataTable();
for (int i = 0; i < 5; i++)
{
dt.AddTable1Row(i.ToString(), "name" + i.ToString());
}
// Open the connection using the connection string.
using (SqlCeConnection con = new SqlCeConnection(conString))
{
try
{
var cmd = con.CreateCommand();
con.Open();
cmd.CommandType = CommandType.TableDirect;
cmd.CommandText = "Table1";
var rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
var rec = rs.CreateRecord();
foreach (DataRow dr in dt.Rows)
{
rec.SetString(0, dr["ID"].ToString());
rec.SetString(1, dr["Name"].ToString());
rs.Insert(rec);
}
rs.Close();
rs.Dispose();
cmd.Dispose();
}
catch (Exception ex) { }
}
}
您面临的问题是:http://erikej.blogspot.com/2010/05/faq-why-does-my-changes-not-get-saved.html