2013-01-14 127 views
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 

回答

5

的查詢中的問號是無效的。您需要改爲使用參數名稱:

command = New SqlCommand("insert into user_master values (@us_user_id, @us_role,@us_fname,@us_lname,@us_pass)", myConnection)