OSx平台下,使用SqlDataAdapter.Update方法出错。
public int BulkToDB()
{
int res = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.SqlConn))
{
using (SqlCommand cmd = conn.CreateCommand())
{
try
{
cmd.CommandText = "select * from tmpTbale where 1=2";
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
DataRow ndr = dt.NewRow();
ndr[0] = 1;
ndr[1] = "name";
ndr[2] = "male";
dt.Rows.Add(ndr);
SqlCommandBuilder scb = new SqlCommandBuilder(adpt);
res = adpt.Update(dt);
dt.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}
}
return res;
}
以上的代码就是一个简单的将一行数据通过SqlDataAdapter.Update()方法,提交插入到数据表。相同的代码相同的数据库,在WIN平台下顺利执行插入生效。但在OSx平台(本人的MacBook Pro)使用最新的VS for Mac 的IDE工具执行这段代码后,显示如下报错:
Update requires the command clone to have a connection object. The Connection property of the command clone has not been initialized.
我不知道这是OSx平台下FrameWork的BUG,还是这个方法在OSx平台有其他的写法?不知道有没有其他朋友也遇到过这样的情况。
乔