1

I am making a database system. I've implemented the INSERT function properly but when I tried implementing the UPDATE function, I couldn't make any changes to the database. I don;t know where I went wrong.
Note: username is declared as string

Here is the function handling the UPDATE:

private void btnUpdate_Click(object sender, EventArgs e)
    {

        string q = "UPDATE [registrationinfo] SET [Password]='?', [EmailAdd]='?', [HomeAdd]='?' WHERE [Username]='?'";

        OleDbConnection connect = new OleDbConnection(MyConnectionString);
        connect.Open();
        try
        {
            OleDbCommand command = new OleDbCommand(q,connect);

            command.Parameters.AddWithValue("@Password", txt_password.Text);
            command.Parameters.AddWithValue("@EmailAdd", txt_eadd.Text);
            command.Parameters.AddWithValue("@HomeAdd", txt_homeadd.Text);
            command.Parameters.AddWithValue("Username", username);

            command.ExecuteNonQuery();

            txt_password.Clear();
            txt_eadd.Clear();
            txt_homeadd.Clear();
            txt_conPass.Clear();
        }
        catch (Exception ex)
        {
            connect.Close();
            MessageBox.Show(ex.Message.ToString());
        }

        connect.Close();            
    }

1 Answer 1

3

When using a parameterized query you do not need to put single quotes (') around text parameters in your CommandText, so you should be using something like this:

string q = "UPDATE [registrationinfo] SET [Password]=?, [EmailAdd]=?, [HomeAdd]=? WHERE [Username]=?";
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! That worked it... :) appreciate it much... now I can graduate... ~~
@marijanluvlee Don't forget to mark this as the correct answer, if it answers your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.