ACCESS/SQL - Too Few Parameters

后端 未结 2 1390
一生所求
一生所求 2020-12-22 13:39

I am using the code below to create a new record in the \"transactions table\" the second line of the insert statement is throwing an error: Too few parameters. I have doubl

2条回答
  •  佛祖请我去吃肉
    2020-12-22 14:04

    As others have suggested, using a parameterized query is a much better way of doing what you're attempting to do. Try something like this:

    Dim qdf As DAO.QueryDef
    Set qdf = dbs.CreateQueryDef("", _
            "PARAMETERS prmCustomerID Long, prmMealID Long, prmTransactionAmount Currency, prmTransactionDate DateTime;" & _
            "INSERT INTO dbo_Transactions (CustomerID, MealID, TransactionAmount, TransactionDate) " & _
            "VALUES ([prmCustomerID], [prmMealID], [prmTransactionAmount], [prmTransactionDate]) ")
    qdf!prmCustomerID = txtCustomerID.Value
    qdf!prmMealID = txtMealType.Value
    qdf!prmTransactionAmount = txtCharge.Value
    qdf!prmTransactionDate = Date()
    qdf.Execute dbFailOnError
    Set qdf = nothing
    

提交回复
热议问题