其实非常简单,就是用SqlDataAdapter的update方法就行了。主要代码例如下所示:
private void update()
{
string link = ConfigurationSettings.AppSettings["link_local"].ToString();
SqlConnection conn = new SqlConnection(link);
SqlDataAdapter da = new SqlDataAdapter("SELECT order_id, contract FROM linhai", conn);
DataSet ds = new DataSet();
da.Fill(ds, "linhai");
da.UpdateCommand = new SqlCommand("UPDATE linhai SET contract = @contract " + "WHERE order_id = @order_id" , conn);
da.UpdateCommand.Parameters.Add("@contract", SqlDbType.NVarChar, 15, "contract");
da.UpdateCommand.Parameters.Add("@order_id", SqlDbType.NVarChar, 15, "order_id");
ds.Tables["linhai"].Rows[0]["contract"] = "PPP";
da.Update(ds.Tables[0]);
}
本文地址:http://com.8s8s.com/it/it42734.htm