0

在执行此代码时,我收到此错误:Syntax error in INSERT INTO statement.

这是我的代码:

Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO Users " & _
                   " (PKID, Username, Password, Email, PasswordQuestion, " & _
                   " PasswordAnswer, IsApproved," & _
                   " Comment, CreationDate, LastPasswordChangedDate, LastActivityDate," & _
                   " ApplicationName, IsLockedOut, LastLockedOutDate," & _
                   " FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, " & _
                   " FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart)" & _
                   " Values (@PKID, @Username, @Password, @Email, @PasswordQuestion, @PasswordAnswer, @IsApproved, @Comment, @CreationDate, @LastPasswordChangedDate, @LastActivityDate, @ApplicationName, @IsLockedOut, @LastLockedOutDate, @FailedPasswordAttemptCount, @FailedPasswordAttemptWindowStart, @FailedPasswordAnswerAttemptCount, @FailedPasswordAnswerAttemptWindowStart)", conn)

            cmd.Parameters.Add("@PKID", OleDbType.Guid).Value = providerUserKey
            cmd.Parameters.Add("@Username", OleDbType.VarChar, 255).Value = username
            cmd.Parameters.Add("@Password", OleDbType.VarChar, 255).Value = EncodePassword(password)
            cmd.Parameters.Add("@Email", OleDbType.VarChar, 128).Value = email
            cmd.Parameters.Add("@PasswordQuestion", OleDbType.VarChar, 255).Value = passwordQuestion
            cmd.Parameters.Add("@PasswordAnswer", OleDbType.VarChar, 255).Value = EncodePassword(passwordAnswer)
            cmd.Parameters.Add("@IsApproved", OleDbType.Boolean).Value = isApproved
            cmd.Parameters.Add("@Comment", OleDbType.VarChar, 255).Value = ""
            cmd.Parameters.Add("@CreationDate", OleDbType.DBTimeStamp).Value = createDate
            cmd.Parameters.Add("@LastPasswordChangedDate", OleDbType.DBTimeStamp).Value = createDate
            cmd.Parameters.Add("@LastActivityDate", OleDbType.DBTimeStamp).Value = createDate
            cmd.Parameters.Add("@ApplicationName", OleDbType.VarChar, 255).Value = pApplicationName
            cmd.Parameters.Add("@IsLockedOut", OleDbType.Boolean).Value = False
            cmd.Parameters.Add("@LastLockedOutDate", OleDbType.DBTimeStamp).Value = createDate
            cmd.Parameters.Add("@FailedPasswordAttemptCount", OleDbType.Integer).Value = 0
            cmd.Parameters.Add("@FailedPasswordAttemptWindowStart", OleDbType.DBTimeStamp).Value = createDate
            cmd.Parameters.Add("@FailedPasswordAnswerAttemptCount", OleDbType.Integer).Value = 0
            cmd.Parameters.Add("@FailedPasswordAnswerAttemptWindowStart", OleDbType.DBTimeStamp).Value = createDate

有人可以解释我的代码中的问题吗?

4

1 回答 1

0

尝试更改OleDbCommand文本

   " Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", conn) 

而不是命名参数

当 CommandType 设置为 Text 时,OLE DB .NET 提供程序不支持将参数传递给 SQL 语句或由 OleDbCommand 调用的存储过程的命名参数。在这种情况下,必须使用问号 (?) 占位符。

于 2013-06-08T19:21:37.020 回答