在执行此代码时,我收到此错误: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
有人可以在我的代码中解释这个问题吗?
答案 0 :(得分:0)
尝试更改OleDbCommand
文字
" Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", conn)
而不是命名参数
OLE DB .NET提供程序不支持传递的命名参数 SQL语句或由a调用的存储过程的参数 CommandType设置为Text时的OleDbCommand。在这种情况下, 必须使用问号(?)占位符。