我正在尝试创建一个用户可以创建帐户的表单,但我收到以下错误:
其他信息:查询表达式中的语法错误(缺少运算符)' @重新输入密码'。
我的代码如下:
Private Sub connect()
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;" 'Sets the provider of the database
dbSource = "Data Source= F:\CarphoneWarehouseDatabase.accdb" 'Sets the location of the database
con.ConnectionString = dbProvider & dbSource 'tells the connection where to find the database and who provides it
con.Open() 'Opens connection
End Sub
Private Sub SubmitBtn_Click(sender As Object, e As EventArgs) Handles SubmitBtn.Click
connect() 'Start connect procedure
Dim sql As String
sqlquery.Connection = con
sqlquery.CommandText = sql
'sql = "INSERT INTO PersonalDetails([Forename],[Surname]) VALUES('test1','test1')" 'Insert the two values into the database
sqlquery.CommandText = "INSERT INTO PersonalDetails([Forename],[Surname],[Username],[Password],[Re-Enter Password],[Email Address],[Re-Enter Email Address],[Date of Birth]) values (@Forename, @Surname, @Username, @Password, @Re-Enter Password, @Email Address, @Re-Enter Email Address, @Date of Birth)"
sqlquery.Parameters.AddWithValue("@Forename", ForenameTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Surname", SurnameTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Username", UsernameTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Password", PasswordTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Re-Enter Password", ReEnterPasswordTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Email Address", EmailAddressTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Re-Enter Email Address", ReEnterEmailTxtBox.Text)
sqlquery.Parameters.AddWithValue("@Date of Birth", DateOfBirthTxtBox.Text)
sqlquery.ExecuteNonQuery()
MsgBox("Row(s) Inserted !! ") 'Displays message box informing the user that the database has been added to
con.Close() 'Connection closed
End Sub
答案 0 :(得分:0)
不允许使用Dash( - ),也不应在@param名称中使用空格
答案 1 :(得分:0)
您应该删除参数标识符名称中的短划线和空格。 例如,在@ReEnterPassword
中重命名@Re-Enter Password