views:

76

answers:

3

I am attempting to pass a text box value into a SQL query, something which just does not want to work for me. The error I receive is 'End of statement expected.'

I presume it is a syntax error on my behalf, I am brand new to ASP and would be grateful if someone could point out where I am going wrong. Below is the code that is causing the problem:

queryCourse = "INSERT INTO users ( [name] ) VALUES ('" + queryCourse += textbox1.text + "');"

I am able to insert hard coded value into the database using this statement so I know that my database connection is not a problem, therefore I presume it is a problem with possibly the concatenation or the way I am referring to the text box.

Thanks in advance.

+1  A: 

It's the code queryCourse += textbox1.text, remove the "queryCourse +=" part and then try it. Unless you actually want to concatenate queryCourse and textbox1.text, in which case remove the "=" (which I suspect you don't, given that you're setting queryCourse to be the SQL you wish to execute).

In other words, your code should read:

queryCourse = "INSERT INTO users ( [name] ) VALUES ('" + textbox1.text + "');"
Rob
Perfect, thank you very much for the quick reply. I guess the tutorial I am following is wrong? Cheers again, sorted.
Ronnie
+1  A: 
queryCourse = "INSERT INTO users ( [name] ) VALUES ('" + textbox1.text + "');"
hallie
+2  A: 
queryCourse = "INSERT INTO users ( [name] ) VALUES ('" + textbox1.text + "');"

But be aware that this allows unfiltered values to be passed and so SQL injection is possible..

Gaby