0

I keep getting this error. I read that OleDb doesn't support named parameters so I changed them to (?, ?).

But is keep getting the same error

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Registration.ImageButton1_Click(Object sender, ImageClickEventArgs e) in c:\Users\Nirre\Desktop\Cti Project\Book Club TRY 2\Registration.aspx.cs:line 51

Here is the code in the .cs class

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    if (IsPostBack)
    {
        OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        conn.Open();
        string insCmd = @"INSERT COUNT(*) INTO Registration(UserName, [Password], EmailAddress, FullName, Country, PasswordRecovery)
                     VALUES (?, ?, ?, ?, ?, ?)";
        OleDbCommand insertUser = new OleDbCommand(insCmd, conn);
        insertUser.Parameters.AddWithValue("@UserName", txtUserName.Text);
        insertUser.Parameters.AddWithValue("@Password", txtPassoword.Text);
        insertUser.Parameters.AddWithValue("@EmailAddress", txtEmail.Text);
        insertUser.Parameters.AddWithValue("@FullName", txtFullName);
        insertUser.Parameters.AddWithValue("@Country", DdlCountry.SelectedItem.ToString());
        insertUser.Parameters.AddWithValue("@PasswordRecovery", txtAnswer.Text);

        try
        {
            insertUser.ExecuteNonQuery();
            conn.Close();
            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            Response.Write(er);
            lblError.Visible = true;
            lblError.Text = "An error has ocured pleas try again...!";
        }
        finally
        {
            // Code
        }
    }
} 
1
  • Plain-text passwords make me sad :( Also... why was this ancient question at the top of the list again? Commented Jul 11, 2018 at 14:23

2 Answers 2

1

INSERT COUNT(*) is not a valid SQL statement, simply remove COUNT(*) and the rest of your code seems correct.

See here for refs

Sign up to request clarification or add additional context in comments.

2 Comments

This is a little strange: Do you mean txtFullName.Text instead of txtFullName?
Thanx Steve, lol it was missing the .Text over looked it think i have been working to long now need a break and some sleep
1
string insCmd = @"INSERT COUNT(*) INTO Registration(UserName, [Password], EmailAddress, FullName, Country, PasswordRecovery)
                     VALUES (?, ?, ?, ?, ?, ?)";

Should be

string insCmd = @"INSERT INTO Registration(UserName, [Password], EmailAddress, FullName, Country, PasswordRecovery)
                     VALUES (@UserName, @Password, @EmailAddress, @FullName, @Country, @PasswordRecovery)";

I don't understand what did you want to do with COUNT. If you want to then return number of affected rows, just add return parameter and assign @@ROWCOUNT to it

Edit: I've never used question marks as parameter placeholders outside Reporting Services so try replacing them with named parameters as shown above.

2 Comments

Yeah soz my bad over looked it "Whoops" but still get the same error
You need ? rather than named placeholders for the OleDb provider.

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.