Jump to content

Syntax error (Missing operator)


Dug
 Share

Recommended Posts

Hi all,Ok I've had to give in and ask again with this one. This is the side of visual basic that I'm not so good at.I was trying to insert a full paragraph into an MS Access database using ASP.NET. The error I get is:

Syntax error (missing operator) in query expression ''The Galaxy's Most Plesant Imaginary Friend','One night'
and my insert SQL statement is:
Dim strSQL as string = "INSERT INTO tblBlog " & _			"(Title, Blog, Username, IP, Added) VALUES (" & _			"'" & tbTitle.Text & "'," & _			"'" & tbBlog.Text & "'," & _			"'" & Session("Name") & "'," & _			"'" & Request.ServerVariables("REMOTE_ADDR") & "'," & _			"'" & Now() & "')"

I googled it, and according to what I found, I need to use the Replace() function and replace all single quotes with two single quotes. Is this the right way to do it? And if so, what would be the best way for my case?When I get this sorted I think the best approach would be for me to create a Namespace for the code so I can access it easily.Any help would be appreciated.Dug

Link to comment
Share on other sites

That seems to be right - e.g.

Dim strSQL as string = "INSERT INTO tblBlog " & _			"(Title, Blog, Username, IP, Added) VALUES (" & _			"'" & replace(tbTitle.Text, "'", "''") & "'," & _			"'" & replace(tbBlog.Text, "'", "''") & "'," & _			"'" & replace(Session("Name"), "'", "''") & "'," & _			"'" & Request.ServerVariables("REMOTE_ADDR") & "'," & _			"'" & Now() & "')"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...