调用insertcourse_registration()时出现以下错误
incorrect syntax near ' ?'
在代码中,当我调用insertcourse_registration im得到上述错误时,你能帮我解决这个问题吗
Public Sub setdata(ByRef lrowcourse_registration As ds_user_master.user_masterRow)
rowuser_master = lrowcourse_registration
End Sub
Public Sub insertcourse_registration()
Try
Try
connectionString = ConfigurationManager.ConnectionStrings("asha_dbConnectionString").ToString
myConnection.ConnectionString = connectionString
myConnection.Open()
MsgBox("Connected to ODBC Database !!")
Catch ex As Exception
End Try
transaction = myConnection.BeginTransaction
command = New SqlCommand("insert into user_master values (?,?,?,?,?)", myConnection)
command.Parameters.Add("@us_user_id", SqlDbType.NVarChar).Value = rowuser_master.us_user_id
command.Parameters.Add("@us_role", SqlDbType.NVarChar).Value = rowuser_master.us_role
command.Parameters.Add("@us_fname", SqlDbType.NVarChar).Value = rowuser_master.us_fname
command.Parameters.Add("@us_lname", SqlDbType.NVarChar).Value = rowuser_master.us_lname
command.Parameters.Add("@us_pass", SqlDbType.NVarChar).Value = rowuser_master.us_pass
command.Connection = myConnection
command.Transaction = transaction
command.ExecuteNonQuery()
transaction.Commit()
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End Sub
最佳答案
查询中的问号无效。您需要改用参数名:
command = New SqlCommand("insert into user_master values (@us_user_id, @us_role,@us_fname,@us_lname,@us_pass)", myConnection)
关于asp.net - '?'附近的语法不正确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14315774/