Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Just as a simple test, I am trying to save html page source to a memo field in Access. The INSERT statement is:

cmdAdd.CommandText = "INSERT INTO tblWebData (PersistentID, ArticleDate, ArticleText, sURL) VALUES" & _
         "('" & sPersistentID & "','" & _
                CDate(lvItem.SubItems(1).Text) & "','" & _
                 sPageText & "','" & _
                 lvItem.SubItems(3).Text & "')"

 

The INSERT worked before I added the sPageText variable (I tested the code by adding a blank string to the database) to the statement.

 

The page source contains all sorts of tick marks, quote marks and other characters typical in html. My guess is that the data is causing the exception error:

 

"ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 

 

 

Question is this: is there a way to store this data while preserving all the html?

 

tia,

flynn

Posted

You need to replace the double, and single quote with 2 of the respective char.

 

Example:

 

sPageText = sPageText.replace("'","''")
sPageText = sPageText.replace(Convert.ToChar(34), Convert.ToChar(34) & Convert.ToChar(34))

 

HTH

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
Or alternatively use a parameterised query. String concatenation is a bad' date=' bad thing - as well as resuling in less maintainable code (like needed to manipulate strings) it also introduces the possibilty of security exploints such as injections.[/quote']

 

Absolutely, I agree. I was just doing a quick test to see the problems I would run into by using the "hyperlink" data type inside Access.

 

Thanks folks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...