Reputation: 25
I m working with c#, in this i want to delete record from the form for that i have the following code..
private void button3_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany.mdb";
con.Open();
string sql = "DELETE FROM tblCompany WHERE (CoCode = 1)";
}
but i m not getting the answer...
Upvotes: 0
Views: 56
Reputation: 2527
You need to setup an OleDbCommand
The full code for your case,
private void button3_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany.mdb";
string sql = "DELETE FROM tblCompany WHERE (CoCode = 1)";
con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
}
For more information of the whole implementation, read here http://www.java2s.com/Code/CSharp/Database-ADO.net/DeletedatabaserecordsthroughOleDbCommandandverifytheresults.htm
Upvotes: 2