Question

am a beginner in C#. am trying to create a website

i have a problem to give a delete option. there is no error showing. But the recrd is not getting deleted

please help

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

thank you

Was it helpful?

Solution

The sql should be

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

Remove * from the SQL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top