繁体   English   中英

在c#中删除创建表单中的记录

[英]Deleting records from the created form in c#

我正在使用c#,在此我想删除表单中的记录,我有以下代码..

     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)";

    }

但我没有得到答案......

您需要设置OleDbCommand

您的案例的完整代码,

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();

    }

有关整个实现的更多信息,请阅读http://www.java2s.com/Code/CSharp/Database-ADO.net/DeletedatabaserecordsthroughOleDbCommandandverifytheresults.htm

您需要使用SQL和连接执行OleCommand

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM