我试图在单个事务中插入巨大的多行。但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) { }
}
}
答案 0 :(得分:1)