如何通过datadapter删除满足条件的特定行 [英] how to delete a specific row satisfing conditio through datadapter

查看:68
本文介绍了如何通过datadapter删除满足条件的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过datadapter删除满足条件的特定行?

How to delete a specific row satisfing conditio through datadapter?

SqlCommand comm = new SqlCommand ("select * from Room",conn);
           SqlCommand comm2 = new SqlCommand ("delete * from Room where Room_N0='"+textBox1.Text+"'",conn);

           SqlCommandBuilder scb = new SqlCommandBuilder (da);
           da.SelectCommand=comm;
           da.Fill(ds,"Room");
           MessageBox.Show(ds.GetXml());

           da.DeleteCommand = comm2;
           DataTable dt = new DataTable();
           dt = ds.Tables[0];
           //DataRow dr = new DataRow();
           foreach(DataRow dr in ds.Tables[0].Select("Room_No = '"+textBox1.Text+"'"))
           {
               dr.Delete();
           }

           MessageBox.Show(ds.GetXml());
           da.Update(ds,"Room");/// the problem is in this line



我的数据集通过以下命令来响应命令,即信息被数据集删除,但是当我更新对数据源的更改时,它会引发错误,即更改未反映在数据库中.



my dataset is responding the command by i.e information is deleted by dataset but when i m updating the changes to datasource it raises the error i.e the changes are not reflected in database.

推荐答案

最简单的方法是
simplest way is
SqlCommand comm2 = new SqlCommand ("delete * from Room where Room_N0=@Room_NO",conn);
comm2.Parameters.Add("@TID", SqlDbType.Int).Value = textBox1.Text;
conn.Open();
comm2.ExecuteNonQuery();
conn.Close();


这将帮助您...


this will help you...


尝试使用da.UpdateCommand = scb.GetUpdateCommand();

此链接将帮助您试用.

http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.update.aspx [ ^ ]
try to use da.UpdateCommand=scb.GetUpdateCommand();

this link will help try out.

http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter.update.aspx[^]


这篇关于如何通过datadapter删除满足条件的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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