Question:
I am trying to update an Access database with an ASP page. My ASP page contains a guest book with first name, last name, and other relevant text boxes. After pressing the submit button on the ASP form, the text box values are sent to the server and my script places them into two Dim variables called FirstName and LastName. A connection with the database is opened called dbconn, and then I attempt to create a new record in the database with this line:
dbconn.execute ("Insert Into GuestTable (FirstName,LastName) Values (FirstString, LastString)")
I get this error message:
Too few parameters. Expected 2.
I have tried many variations and nothing has worked.
Answer:
You cannot use the variable NAMES inside your SQL string. You need to use the variable VALUES. Concatenate the variable values to generate the SQL statement and then proceed.
Dim strSQLstrSQL = "Insert Into GuestTable (FirstName,LastName) Values (" & FirstString & "," & LastString & ")"dbconn.execute (strSQL)
Assuming that the variables hold string values, you will need to enclose them within single quotes:
strSQL = "Insert Into GuestTable (FirstName,LastName) Values ('" & FirstString & "', '" & LastString & "')"