使用OleDbAdapter删除记录

时间:2011-10-26 10:32:05

标签: c# oledbdataadapter

我是C#的初学者。我正在尝试创建一个网站

我有一个问题是提供删除选项。没有错误显示。但recrd没有被删除

请帮助

protected void delete_button_Click(object sender,EventArgs e)         {

        string uname;
        string pwd;

        uname = txt_user.Text;
        pwd = txt_pass.Text;



        string connetionString = null;
        OleDbConnection connection;
        OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
        string sql = null;
        connetionString = "Provider=SQLOLEDB;dsn=xe;User id=sa;password=password123";
        connection = new OleDbConnection(connetionString);

        sql = "DELETE * FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'";
        try
        {
            connection.Open();
            oledbAdapter.DeleteCommand = connection.CreateCommand();
            oledbAdapter.DeleteCommand.CommandText = sql;

            oledbAdapter.DeleteCommand.ExecuteNonQuery();
            Label4.Text = "deleted";
        }

谢谢

1 个答案:

答案 0 :(得分:0)

sql应该是

"DELETE FROM Login WHERE username='" + uname + "' and password='" +pwd+ "'"

从SQL中删除*。