469,306 Members | 1,983 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Trying to input xml data type, "Incorrect syntax near '<'."

abehm
35
Hey everyone,
I'm trying to input a string as an xml data type into sql server, but i keep getting this error. Am I doing this incorrectly, or do i need to format the string?

Expand|Select|Wrap|Line Numbers
  1. XmlDocument mydoc = new XmlDocument();
  2. SqlCommand sqlCommand;
  3.  
  4. mydoc.Load(xmlDir + "temp.xml");
  5.  
  6. string tempXML = mydoc.OuterXml;
  7.  
  8. string sqlcom = "INSERT INTO Config.TestBooth  (TestBoothID,TestBoothName,Config) "
  9. + "VALUES (" + testBoothID + ", " + testBoothName + ", " + tempXML + ")";
  10. sqlCommand = new SqlCommand(sqlcom);
  11. sqlCommand.Connection = sql;
  12. sql.Open();
  13. sqlCommand.ExecuteNonQuery();
  14. sqlCommand.Connection.Close();
  15.  
Jun 29 '07 #1
2 1936
abehm
35
I'm thinking i might be trying to insert it into the wrong table which is why it's not recognizing the xml data type. Is there a way to check if the table exists?
or should it just give me an error saying table does not exist?
Jun 29 '07 #2
abehm
35
figured it out.

i just had to put apostrophes before and after the tempXML in the insert statement.
Jun 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by F. Da Costa | last post: by
3 posts views Thread by Michael | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.