Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to delete a specific row satisfing conditio through datadapter?
C#
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.
Posted
Updated 30-Jun-11 20:21pm
v3
Comments
Vivek Krishnamurthy 30-Jun-11 13:18pm    
What is the problem in that line, can you be more specific.
Are you geting any error ? you can use Improve question widget.

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...
 
Share this answer
 
v2
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900