|
初学者,希望大侠们能详细解答一下,代码:
SqlConnection thisConnection = new SqlConnection("Data Source = PC-20130318zrgn; Initial Catalog = UserInformation; Integrated Security = True");
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT * from UsrInfo", thisConnection);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "UsrInfo");
Console.WriteLine("Name before change: {0}", thisDataSet.Tables["UsrInfo"].Rows[1]["ID"]);
thisDataSet.Tables["UsrInfo"].Rows[1]["ID"] = 110;
thisAdapter.Update(thisDataSet, "UsrInfo");
Console.WriteLine("Name after change: {0}", thisDataSet.Tables["UsrInfo"].Rows[1]["ID"]);
thisConnection.Close();
Console.WriteLine("Program finished, Press Enter/Return to continue.");
Console.ReadKey();
运行是,控制台只显示:ID before change 这一行,一闪就关了,而且数据库里相应的值没有改变。注释Update后能全显示,但这只是改变了内存中相应值,数据库里的仍然没改变。
谢谢。
补充内容 (2013-12-7 10:37):
知道哪儿错了,在Update前需要设置主键,但不知如何设置,忘赐教。谢谢。 |
|