本文介绍了如何通过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.

推荐答案

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...



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

08-20 10:56
查看更多