0

我不断收到此错误。我读到 OleDb 不支持命名参数,所以我将它们更改为(?, ?).

但是不断收到同样的错误

System.Data.OleDb.OleDbException:INSERT INTO 语句中的语法错误。在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data。 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 行为,字符串方法)在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() 的 OleDb.OleDbCommand.ExecuteCommand(CommandBehavior 行为,Object& executeResult) 在 Registration.ImageButton1_Click(对象发送者,ImageClickEventArgs e) 在 c:\Users\Nirre\Desktop\Cti Project\Book Club TRY 2\Registration.aspx.cs:line 51

这是 .cs 类中的代码

 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
        }
    }
} 
4

2 回答 2

1

INSERT COUNT(*)不是有效的 SQL 语句,只需删除COUNT(*),其余代码似乎正确。

请参阅此处以获取参考

于 2012-06-18T14:03:52.173 回答
1
string insCmd = @"INSERT COUNT(*) INTO Registration(UserName, [Password], EmailAddress, FullName, Country, PasswordRecovery)
                     VALUES (?, ?, ?, ?, ?, ?)";

应该

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

我不明白你想用 COUNT 做什么。如果您想返回受影响的行数,只需添加返回参数并将@@ROWCOUNT 分配给它

编辑:我从未在 Reporting Services 之外使用问号作为参数占位符,因此请尝试用命名参数替换它们,如上所示。

于 2012-06-18T14:04:17.073 回答