使用数据集更新方法删除:概念不明确 [英] Delete Using Dataset Update Method : Concept Not clear

查看:108
本文介绍了使用数据集更新方法删除:概念不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//Delete Record : Disconnected

public void DeleteBook(int BookId)
    {
      1)  DataRow dr1 = ds.Tables["tbl_Books"].NewRow();
      2) dr1 = ds.Tables["tbl_Books"].Rows.Find(BookId);
      3)  dr1.Delete();       
      4)  SqlCommand delcmd = new SqlCommand("Delete from tbl_Books where BookId="  BookId.ToString(), cn);
      5)  SqlCommandBuilder cmdb = new SqlCommandBuilder(da1);
      6)  da.DeleteCommand = delcmd;
      7)  da.Update(ds.Tables ["tbl_Books"]);
    
    }



上面的代码工作正常.但是概念还不清楚.
在执行语句(3)之后,特定行将从数据集中移出.
然后,Update Commad(即Statement(7))应将数据更新到数据库.

那么,语句(4),(5)和(6)的用途是什么.
没有删除查询",还有其他写上述代码的方法吗?
如果是这样,请证明代码....



The Above code is working fine. But the concept is not clear.
After Execution of Statement No.(3) the particular row is romoved from the DataSet.
Then the Update Commad (ie Statement(7)) should update the data to database.

Then what is the use of Statement (4),(5) and (6).
Is there any other way to write above code without "Delete Query"
If so please prove the code....

推荐答案

//我得到了答案..我期望的结果如下..
//================================================ =========
公共无效DeleteBook(int BookId)
{
DataRow dr1 = ds.Tables ["tbl_Books"].NewRow();
dr1 = ds.Tables ["tbl_Books"].Rows.Find(BookId);
dr1.Delete();
SqlCommandBuilder cmdb =新的SqlCommandBuilder(da);
da.Update(ds.Tables ["tbl_Books"]);
}
//I Got the answer .. What i am expecting was as follows..
//=========================================================
public void DeleteBook(int BookId)
{
DataRow dr1 = ds.Tables["tbl_Books"].NewRow();
dr1 = ds.Tables["tbl_Books"].Rows.Find(BookId);
dr1.Delete();
SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
da.Update(ds.Tables ["tbl_Books"]);
}


这篇关于使用数据集更新方法删除:概念不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆