这个问题我已解决
可是删数据时碰到错误了,请大家帮我看看。
try
{
DataRow newRow=DS商品大类.Tables["B商品大类"].NewRow();
newRow["商品大类号"]=商品大类号.Text ;
newRow["商品大类名"]=商品大类名.Text ;
DS商品大类.Tables ["B商品大类"].Rows.Remove(newRow);
SQLDAP商品大类.Update(DS商品大类,"B商品大类");
}
catch (Exception k)
{
MessageBox.Show(k.Message) ;
}
可是删数据时碰到错误了,请大家帮我看看。
try
{
DataRow newRow=DS商品大类.Tables["B商品大类"].NewRow();
newRow["商品大类号"]=商品大类号.Text ;
newRow["商品大类名"]=商品大类名.Text ;
DS商品大类.Tables ["B商品大类"].Rows.Remove(newRow);
SQLDAP商品大类.Update(DS商品大类,"B商品大类");
}
catch (Exception k)
{
MessageBox.Show(k.Message) ;
}
你的newRow并没有加到table里,怎么删除呢?
有不对的地方请指正。谢谢~
DataTable dt = myDataSet.Tables ["B商品大类"];
DataColumn [] dc = new DataColumn[1];
dc[0] = dt.Columns ["B商品大类"];
dt.PrimaryKey = dc;
object key = treeViewMain.SelectedNode .Text .Trim (); //查找对应记录
DataRow dr = dt.Rows.Find (key);
dr.Delete ();
//更新数据库信息
SQLDAP商品大类.Update(DS商品大类,"B商品大类");
改成这样:
//删除对应记录的信息
DataTable dt = myDataSet.Tables ["B商品大类"];
DataColumn [] dc = new DataColumn[1];
dc[0] = dt.Columns ["B商品大类"];
dt.PrimaryKey = dc;
object key = 商品大类号.Text ; //查找对应记录
DataRow dr = dt.Rows.Find (key);
dr.Delete ();
//更新数据库信息
SQLDAP商品大类.Update(DS商品大类,"B商品大类");
dc[0] = dt.Columns ["B商品大类"];改成
dc[0] = dt.Columns ["商品大类号"];