Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Mar 24, 2000

Write Correct INSERT SQL Statement With ASP

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 strSQL

strSQL = "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 & "')"
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date