A1VBCode Forums

delete in c# .net


http://www.a1vbcode.com/vbforums/Topic30182.aspx

By annaharris - 5/23/2013

did you solve the issue using the delete query instead of that complex code?
By marcus416 - 3/12/2011

i try to delete a record using this code;



string ConStr = "Provider=Microsoft.Jet.OleDB.4.0; Data Source =" + Application.StartupPath + "\\db1.mdb";

using (OleDbConnection Conn = new OleDbConnection(ConStr))

{



Conn.Open();



OleDbCommand Cmd = new OleDbCommand("Select * from table1 WHERE PatientNo='" + "11-11001" + "'", Conn);

OleDbDataAdapter dAdapter = new OleDbDataAdapter(Cmd);

DataSet dDataSet = new DataSet();



dAdapter.Fill(dDataSet, "table1");



dDataSet.Tables["table1"].Rows[0].Delete();



dAdapter.Update(dDataSet, "table1");

dDataSet.AcceptChanges();



Conn.Close();



}




but the message is: Update requires a valid DeleteCommand when passed DataRow collection with delete rows.