1

调用 insertcourse_registration() 时出现以下错误

incorrect syntax near ' ?' 

在我调用 insertcourse_registration 的代码中,我得到了上述错误,你能帮我解决这个问题吗

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
4

1 回答 1

5

查询中的问号无效。您需要改用参数名称:

command = New SqlCommand("insert into user_master values (@us_user_id, @us_role,@us_fname,@us_lname,@us_pass)", myConnection)
于 2013-01-14T09:23:41.970 回答