SqlDataAdapter更新记录问题
以下这段代码为添加记录,本人想用同样的方法更新一条记录如何修改下面这段代码,假设SQL为: string sql = "select * from c_g_products where id=2 ";
请帮忙写出代码。
obj.New();
string sql = "select * from c_g_products ";
obj.Open();
adp = new SqlDataAdapter(sql,obj.strconn());
adp.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlCommandBuilder dbcb = new SqlCommandBuilder(adp);
ds = new DataSet();
adp.Fill(ds, "ds ");
DataTable dbTable = ds.Tables[ "ds "];
DataRow dbRow = dbTable.NewRow();
dbRow[ "f_customerid "] = customerid;
dbRow[ "f_productname "] = productname.Value.Trim();
dbRow[ "f_productxh "] = productxh.Value.Trim();
dbRow[ "f_productlx "] = productlx.SelectedItem.Value.Trim();
dbTable.Rows.Add(dbRow);
adp.Update(ds, "ds ");
obj.Close();
------解决方案--------------------string sql = "select * from c_g_products where id=2 ";
DataRow dbRow = dbTable.Rows[0];
dbRow[ "f_customerid "] = customerid;
dbRow[ "f_productname "] = productname.Value.Trim();
dbRow[ "f_productxh "] = productxh.Value.Trim();
dbRow[ "f_productlx "] = productlx.SelectedItem.Value.Trim();
adp.Update(ds, "ds ");
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
最新版本:20070130
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
------解决方案--------------------ds.Tables[0].Rows.Count> 0