Dug Posted February 6, 2008 Share Posted February 6, 2008 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 More sharing options...
Synook Posted February 7, 2008 Share Posted February 7, 2008 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 More sharing options...
Dug Posted February 7, 2008 Author Share Posted February 7, 2008 Hey, thanks for that, it worked! All sorted now. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.