Jump to content

Syntax error (Missing operator)


Dug

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...