dataadapter update方法的使用

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:48:50
SqlConnection sql_con = new SqlConnection("Data Source=PC2009102418VEJ\\SQLEXPRESS;Initial Catalog=xscj;Integrated Security=True");
sql_con.Open();
SqlCommand sql_com = new SqlCommand("SearchByXH", sql_con);
sql_com.CommandType = CommandType.StoredProcedure;

sql_com.Parameters.Add("@xh", SqlDbType.Char, 10);
sql_com.Parameters["@xh"].Value = textBox1.Text;

SqlDataAdapter sda = new SqlDataAdapter(sql_com);
DataSet ds = new DataSet();
sda.Fill(ds);
sda.update(ds.tables[0])

上面的SQL语句是用存储过程来完成的.想通过update来更新
存储过程是执行 select * from xscj where 学号=@xh

但是update无法修改查询到的结果啊 ???是怎么回事????
到底update该怎么用啊

update 的用法是
update 表名 set 列名 = 更新值 [where 条件]

如果你的updatae无法查询到修改的结果的话
你把sql语句改成这个样子

update 表名 set 列明 = 更新值 where 字段名 in (查询语句)

因为你update无噶修改查询到得结果可能是因为查询到得结果太多了,而update 只能修改一行,如果使用到关键字in的话,就会修改查询到的结果中的每一行,试试吧