使用ADO.NET进行数据库Update的时候不会报错,但是在Sql Server里查询不到更新后的结果.
向各位大大求助...
代码如下:
const string strCnn = "Data Source=localhost;Initial Catalog=CentralDB;Integrated Security=True";
SqlConnection centralCnn = new SqlConnection(strCnn);
try
{
centralCnn.Open(); SqlDataAdapter centralDa = new SqlDataAdapter("select * from t_tdd", centralCnn);
SqlCommandBuilder cb = new SqlCommandBuilder(centralDa);
DataSet centralDs = new DataSet();
centralDa.Fill(centralDs, "t_tdd");
JsbDs jsbDs = new JsbDs();
JsbDsTableAdapters.t_tddTableAdapter t_tddTA = new JsbDsTableAdapters.t_tddTableAdapter();
t_tddTA.Fill(jsbDs.t_tdd);
DataTable centralDt = new DataTable();
centralDt = jsbDs.t_tdd.Copy();
for (int n = 0; n < centralDt.Rows.Count; n++)
{
centralDs.Tables["t_tdd"].ImportRow(centralDt.Rows[n]);
}
centralDa.Update(centralDs, "t_tdd");
// If no error occurs.
Console.WriteLine("Succeed.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
centralCnn.Close();
}
向各位大大求助...
代码如下:
const string strCnn = "Data Source=localhost;Initial Catalog=CentralDB;Integrated Security=True";
SqlConnection centralCnn = new SqlConnection(strCnn);
try
{
centralCnn.Open(); SqlDataAdapter centralDa = new SqlDataAdapter("select * from t_tdd", centralCnn);
SqlCommandBuilder cb = new SqlCommandBuilder(centralDa);
DataSet centralDs = new DataSet();
centralDa.Fill(centralDs, "t_tdd");
JsbDs jsbDs = new JsbDs();
JsbDsTableAdapters.t_tddTableAdapter t_tddTA = new JsbDsTableAdapters.t_tddTableAdapter();
t_tddTA.Fill(jsbDs.t_tdd);
DataTable centralDt = new DataTable();
centralDt = jsbDs.t_tdd.Copy();
for (int n = 0; n < centralDt.Rows.Count; n++)
{
centralDs.Tables["t_tdd"].ImportRow(centralDt.Rows[n]);
}
centralDa.Update(centralDs, "t_tdd");
// If no error occurs.
Console.WriteLine("Succeed.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
centralCnn.Close();
}
在Sql Profiler中查看,没有写入的动作
没有写入动作就是你update有问题,把它的代码贴出来看看
如果你update用了事物最后没有提交,虽然代码提示成功,但数据库的值也不会改变的,建议加断点跟踪一下,就知道了。
Update()在主贴上已有,即:
centralDa.Update(centralDs, "t_tdd");
我试了下,加上了:
centralDs.AcceptChanges();
依然没有解决问题,貌似在调用Update()方法时会自动调用AcceptChanges()