473,624 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to input xml data type as string, get error "Incorrect syntax near '<'."

abehm
35 New Member
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
6 4049
jhardman
3,406 Recognized Expert Specialist
the only problem is that there must be some special characters (for sql) in your string. a quote mark or parenthese or some such. print out your sqlcon to make sure. You may need to run some kind of replace function on the string before you pass it.

Let me know if this helps.

Jared
Jun 29 '07 #2
abehm
35 New Member
So I added a 'Response.Write (sqlcom);' line, and it took me to a new page that says "The XML page cannot be displayed "
"Invalid at the top level of the document. Error processing resource 'http://localhost:1322/WebSite3/Default.aspx'. Line 1,...

INSERT INTO Config.TestBoot h (TestBoothID,Te stBoothName,Con fig) VALUES (1, .326, <?xml version="1.0" encoding="utf-8"?>..."
Jun 29 '07 #3
abehm
35 New Member
if i type sqlcom in the Immediate Window it reads:
Expand|Select|Wrap|Line Numbers
  1. ""INSERT INTO Config.TestBooth (TestBoothID,TestBoothName,Config) VALUES (1, .326, <?xml version=\"1.0\" encoding=\"utf-8\"?><Config><Testbooth> <TestBoothID>1</TestBoothID><Vertical>0.340999990701675</Vertical> <Horizontal>5777</Horizontal><Diagonal>193</Diagonal> <AreaIN>0.32600000500679</AreaIN><AreaFT>0.340999990701675</AreaFT> <ScreenGain>0</ScreenGain><MeasurementType>2</MeasurementType> </Testbooth></Config>)"
  2.  
Jun 29 '07 #4
jhardman
3,406 Recognized Expert Specialist
OK, I often suggest that coders switch from "Insert" to "addnew" and I think that may help in this case, it looks like the quote marks in the xml string are messing up your insert statement. syntax for addnew is:
Expand|Select|Wrap|Line Numbers
  1. query="SELECT * FROM config.testBooth"
  2. objRS.open query, objConn, adOpenDynamic, adLockOptimistic
  3. objRS.addNew
  4. objRS("TestBoothID") = 1
  5. objRS("TestBoothName") = 0.326
  6. objRS("config") = xmlConfigString
  7. objRS.update
I know it looks longer, but it executes at the same speed. Let me know if this helps.

Jared
Jun 29 '07 #5
abehm
35 New Member
OK, I often suggest that coders switch from "Insert" to "addnew" and I think that may help in this case, it looks like the quote marks in the xml string are messing up your insert statement. syntax for addnew is:
Expand|Select|Wrap|Line Numbers
  1. query="SELECT * FROM config.testBooth"
  2. objRS.open query, objConn, adOpenDynamic, adLockOptimistic
  3. objRS.addNew
  4. objRS("TestBoothID") = 1
  5. objRS("TestBoothName") = 0.326
  6. objRS("config") = xmlConfigString
  7. objRS.update
I know it looks longer, but it executes at the same speed. Let me know if this helps.

Jared
Thanks for your help Jared, but I ended up solving the issue when I changed the sql statement to this (with the apostrophes):
Expand|Select|Wrap|Line Numbers
  1.  string sqlcom = "INSERT INTO Config.TestBooth (TestBoothID,TestBoothName,Config) " + "VALUES (" + testBoothID.ToString() + ", '" + testBoothName.ToString() + "', '" + tempXML + "')";
  2.  
Jul 3 '07 #6
syed rizwan iqbal shah
2 New Member
try that :)
Expand|Select|Wrap|Line Numbers
  1. xml String
  2.  
  3.  
  4.  
  5. using System;
  6. using System.Collections;
  7. using System.ComponentModel;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Security;
  13. using System.Web.SessionState;
  14. using System.Web.UI;
  15. using System.Web.UI.HtmlControls;
  16. using System.Web.UI.WebControls;
  17. using System.Web.UI.WebControls.WebParts;
  18. using System.Xml.Linq;
  19. using System.Data.OleDb;
  20. using System.Data.SqlClient;
  21. using System.Data.ProviderBase;
  22. using System.Web.Mail;
  23. using System.Xml;
  24. using System.Xml.Serialization;
  25. using System.Xml.Schema;
  26. using System.Text;
  27. using System.Text.RegularExpressions;
  28. using System.IO;
  29.  
  30.  
  31.  
  32. namespace WebApplication3
  33. {
  34.     public partial class _Default : System.Web.UI.Page
  35.     {
  36.         protected void Page_Load(object sender, EventArgs e)
  37.         {
  38.  
  39.         }
  40.  
  41.  
  42.         protected void Button1_Click1(object sender, EventArgs e)
  43.         {
  44.  
  45.  
  46.  
  47.             //for List 1
  48.             for (int i = 0; i < ListSecA.Items.Count; i++)
  49.             {
  50.                 if (ListSecA.Items[i].Selected)
  51.                 {
  52.                     ListSecAValues.Text += ListSecA.Items[i].Value.ToString() + "\n";
  53.                 }
  54.             }
  55.             // For List 2
  56.             for (int x = 0; x < ListSecB.Items.Count; x++)
  57.             {
  58.                 if (ListSecB.Items[x].Selected)
  59.                 {
  60.                     ListSecBValues.Text += ListSecB.Items[x].Value.ToString() + "\n";
  61.                 }
  62.             }
  63.             // For list 3
  64.             for (int z = 0; z < ListBoxHearAbout.Items.Count; z++)
  65.             {
  66.                 if (ListBoxHearAbout.Items[z].Selected)
  67.                 {
  68.                     ListHearValues.Text += ListBoxHearAbout.Items[z].Value.ToString() + "\n";
  69.                 }
  70.             }
  71.  
  72.  
  73.  
  74.  
  75.             string DetailData = "";
  76.             DetailData += TextBoxDetail.Text + TextBoxAddress.Text + TextBoxAddress2.Text + TextBoxCity.Text + TextBoxProvince.Text + TextBoxPostalCode.Text + TextBoxFax.Text + TextBoxWebsite.Text + TextBoxAttendee.Text + ListSecAValues.Text + ListSecBValues.Text + TextBoxSecADate.Text + TextBoxSecBDate.Text + TextBoxNumberAtt.Text + TextBoxSubTotal.Text + TextBoxGst.Text + TextBoxTotalDue.Text + DropdownPayment.SelectedItem.Text + TextBoxCreditCardMonth.Text + TextBoxCreditCardYear.Text + TextBoxCreditCardName.Text + ListHearValues.Text + TextBoxComments.Text;
  77.             System.Xml.Serialization.XmlSerializer serializ = new System.Xml.Serialization.XmlSerializer(DetailData.GetType());
  78.             StringBuilder sb = new StringBuilder();
  79.             TextWriter writer = new StringWriter(sb);
  80.             serializ.Serialize(writer, DetailData);
  81.  
  82.  
  83.                 string str = "";
  84.                 SqlConnection conn = new SqlConnection(
  85.                     "Data source=SYED-PC;Initial Catalog=baass;Integrated Security=True");
  86.  
  87.                 conn.Open();
  88.                 str = "insert into Registrations (EventCode,EventDate,EventTime,EventLocation,Name,Company,Phone,Email,Details) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto','" + TextBoxName.Text.ToString() + "','" + TextBoxCompany.Text.ToString() + "','" + TextBoxPhone.Text + "','" + TextBoxEmail.Text.ToString() + "','" + writer.ToString()+ "')";
  89.  
  90.  
  91.                 //sr = "insert into Registrations (EventCode,EventDate,EventTime,EventLocation,Name,Company,Phone,Email,Details) values ('Event of Toronto','03/15/2008','09:30:00 AM','Toronto','" + Request.Form.Get("TextBoxName.text").ToString() + "','" + Request.Form.Get("TextBoxCompany.text").ToString() + "','" + Request.Form.Get("TextBoxPhone.text") + "','" + Request.Form.Get("TextBoxEmail.text").ToString() + "','" + Request.Form.Get("TextBoxDetail.text").ToString() + "')";
  92.  
  93.  
  94.  
  95.                 SqlCommand md = new SqlCommand(str, conn);
  96.  
  97.                 //int y = md.ExecuteNonQuery();
  98.                 int g = md.ExecuteNonQuery();
  99.  
  100.  
  101.                 conn.Close();
  102.                 MailMessage mails = new MailMessage();
  103.  
  104.                 mails.To = TextBoxEmail.Text;
  105.                 //mails.Bcc = "abcdef@gmail.com";
  106.                 mails.From = "WebRegistration@BAASS.accdoc.com";
  107.                 mails.Subject = "Welcome: " + TextBoxName;
  108.  
  109.                 mails.Body = "Hello " + TextBoxName.Text +
  110.                     "\n \n \n Thank you for your registration request. You have successfully registered \n for the following BAASS Training Course(s). \n \n Series A Course(s):"
  111.                     + ListSecAValues.Text + "\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text + " \n Time(s) for Series A Course(s): \n \n Series B Course(s):" 
  112.                     + ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text + "\n Time(s) for Series B Course(s): \n \n \n Registrant Name(s):" 
  113.                     + TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text + " \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:" 
  114.                     + TextBoxTotalDue.Text + " \n Location: BAASS Training Centre,  1200 Centre Street, Thornhill, ON L4J 3M9 \n \n \n Please visit www.baass.com/baass01.nsf/pages/Contact.html#map "+
  115.                     "for a map to the location. \n \n \n Please do not hesitate to contact us if you require further information. \n \n \n Thank you, \n \n \n Susie Pedota \n Consultant Office Manager "+
  116.                     "\n BAASS Business Solutions Inc.\n Tel: 905.660.1285 Ext. 237 \n Toronto Tel: 416.777.1285 \n Fax: 905.660.3823 \n spedota@baass.com \n www.baass.com \n Bringing Technology to Business";
  117.  
  118.                 SmtpMail.SmtpServer = "localhost";
  119.                 SmtpMail.Send(mails);
  120.  
  121.                 MailMessage myself = new MailMessage();
  122.                 myself.To = "sshah@baass.com";
  123.                 myself.From = "WebRegistration@BAASS.accdoc.com";
  124.                 myself.Subject = "BAASS Thornhill Online Course Registration Confirmation";
  125.                 myself.Body = "Hello " + TextBoxName.Text +
  126.                     "\n \n \n Thank you for your registration request. You have successfully" +
  127.                     "registered \n for the following BAASS Training Course(s). \n \n Series A Course(s):" + ListSecAValues.Text +
  128.                     "\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text + 
  129.                     " \n Time(s) for Series A Course(s): \n \n Series B Course(s):"
  130.                     + ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text +
  131.                     "\n Time(s) for Series B Course(s): \n \n \n Registrant Name(s):"
  132.                     + TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text +
  133.                     " \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:" + TextBoxTotalDue.Text +
  134.                     " \n Location: BAASS Training Centre,  1200 Centre Street, Thornhill, ON L4J 3M9 \n \n \n Please visit "+
  135.                     "www.baass.com/baass01.nsf/pages/Contact.html#map for a map to the location. \n \n \n Please do not hesitate"+
  136.                     " to contact us if you require further information. \n \n \n Thank you, \n \n \n Susie Pedota \n Consultant Office Manager "+
  137.                     "\n BAASS Business Solutions Inc.\n Tel: 905.660.1285 Ext. 237 \n Toronto Tel: 416.777.1285 \n Fax: 905.660.3823 \n spedota@baass.com "+
  138.                     "\n www.baass.com \n Bringing Technology to Business \n \n \n \n ----------------------------------------------------------------------------------- "+
  139.                     "\n The following message was sent as a Online Course Registration request. \n Clicking on reply or reply with history will allow you to respond to this \n request. \n \n Registrant Name(s):" 
  140.                     + TextBoxName.Text + "\n \n \n Company Name: " + TextBoxCompany.Text + " \n Address 1: " + TextBoxAddress.Text + "Address 2: " + TextBoxAddress2.Text + " \n City: " + TextBoxCity.Text + " \n Province: " 
  141.                     + TextBoxProvince.Text + " \n Postal Code: " + TextBoxPostalCode.Text +
  142.                     " \n Phone Number: " + TextBoxPhone.Text + " \n Fax Number: " + TextBoxFax.Text + " \n Person's Email: " + TextBoxEmail.Text + " \n Website: " + TextBoxWebsite.Text +
  143.                     " \n Number of Attendees: " + TextBoxNumberAtt.Text + " \n \n Series A Course(s):"
  144.                     + ListSecAValues.Text + "\n \n Date(s) for Series A Course(s): " + TextBoxSecADate.Text + " \n \n Series B Course(s):" + ListSecBValues.Text + " \n \n Date(s) for Series B Course(s):" + TextBoxSecBDate.Text + " \n Subtotal Amount: " 
  145.                     + TextBoxSubTotal.Text + " \n GST Amount: " + TextBoxGst.Text + " \n Total Due: " + TextBoxTotalDue.Text + " \n Payment Method: " + DropdownPayment.SelectedItem.Text + " \n Credit Card Number: " + TextBoxCreditCard.Text + " \n Expiry Date: MONTH: "
  146.                     + TextBoxCreditCardMonth.Text + " Year: " + TextBoxCreditCardYear.Text + " \n Card Holder Name: " + TextBoxCreditCardName.Text + " \n How did you hear about this course: " + ListHearValues.Text + " \n Message: " + TextBoxComments.Text +
  147.                     " \n -----------------------------------------------------------------------------------\n";
  148.  
  149.  
  150.                 SmtpMail.SmtpServer = "Exchange";
  151.  
  152.                 SmtpMail.Send(myself);
  153.                 Response.Redirect("Thanks.aspx");
Mar 3 '08 #7

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

Similar topics

5
4492
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the -q64 option in xlC compiler. And we are able to link all these libraries to one of the main applications and generate an executable. SKLoader. But, when we try to run this main executable, we are getting the following errors:
8
46179
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine where the inital " started? I find myself adding /* */ blocks or cutting/pasting sections of code out in order to find where the error occured. Wouldn't it it be nice if the warning message included the line in teh source where the initial quote ...
1
1401
mikeinspain
by: mikeinspain | last post by:
Hi Guys I am getting the following error: Parse error: syntax error, unexpected '}' in /home/9144/domains/cbweb.co.uk/html/propertyEnquiry.php on line 5 This is the referring PHP code... <?php ('_class_functions/rental_sales_shim.php'); require_once('_class_functions/enquiryList.php');
2
3500
by: Shrutisinha | last post by:
I am getting this error in unix .. syntax error near unexpected token `(' when i am running my parser , can anybody help me plzz .. i am new to all this thanks
1
1215
by: fredie108 | last post by:
I've installed a link request script and when testing the link request form I get this: Parse error: syntax error, unexpected '@' in /home/mybusiness/public_html/output.php on line 91 I then went to output.php: . "Site_Description: $Site_Description\n" . "upload: $upload_URL\n" .......................(this should be line 91) . "\n" @mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
3
12535
by: eros | last post by:
ALTER TABLE public.postcodes ALTER COLUMN machi TYPE varchar(100); Error: ERROR: syntax error at or near "TYPE"; Error while executing the query (State:42601, Native Code: 7) I am using WinSQL, Windows XP SP2 Japanese Version, PostgreSQL 8.x. I want to alter my machi field from varchar(30) to varchar(100) TYPE. This is my CREATE TABLE script:
36
7985
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My shortcomings will soon become apparent. I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main "projects" file, and 2 detail files, one for piping and one for equipment. Each of these files will have...
3
2322
by: silambu | last post by:
hi,can anybody tell reason for getting syntax error near , while either updating or inserting records in table
3
6943
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the offending line, but being amateur, I don't know where. I've tried putting one in several places, to no avail. Clearly, to solve this in a smaller period than a week I need someone with more skill to help out. Heh heh. The error is: Parse error:...
10
5644
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject}</li>"; $page_set = get_pages_for_subject($subject);
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.