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? -
XmlDocument mydoc = new XmlDocument();
-
SqlCommand sqlCommand;
-
-
mydoc.Load(xmlDir + "temp.xml");
-
-
string tempXML = mydoc.OuterXml;
-
-
string sqlcom = "INSERT INTO Config.TestBooth (TestBoothID,TestBoothName,Config) "
-
+ "VALUES (" + testBoothID + ", " + testBoothName + ", " + tempXML + ")";
-
sqlCommand = new SqlCommand(sqlcom);
-
sqlCommand.Connection = sql;
-
sql.Open();
-
sqlCommand.ExecuteNonQuery();
-
sqlCommand.Connection.Close();
-
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
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"?>..."
if i type sqlcom in the Immediate Window it reads: -
""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>)"
-
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: - query="SELECT * FROM config.testBooth"
-
objRS.open query, objConn, adOpenDynamic, adLockOptimistic
-
objRS.addNew
-
objRS("TestBoothID") = 1
-
objRS("TestBoothName") = 0.326
-
objRS("config") = xmlConfigString
-
objRS.update
I know it looks longer, but it executes at the same speed. Let me know if this helps.
Jared
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: - query="SELECT * FROM config.testBooth"
-
objRS.open query, objConn, adOpenDynamic, adLockOptimistic
-
objRS.addNew
-
objRS("TestBoothID") = 1
-
objRS("TestBoothName") = 0.326
-
objRS("config") = xmlConfigString
-
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): -
string sqlcom = "INSERT INTO Config.TestBooth (TestBoothID,TestBoothName,Config) " + "VALUES (" + testBoothID.ToString() + ", '" + testBoothName.ToString() + "', '" + tempXML + "')";
-
try that :) -
xml String
-
-
-
-
using System;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Configuration;
-
using System.Data;
-
using System.Linq;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.SessionState;
-
using System.Web.UI;
-
using System.Web.UI.HtmlControls;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Xml.Linq;
-
using System.Data.OleDb;
-
using System.Data.SqlClient;
-
using System.Data.ProviderBase;
-
using System.Web.Mail;
-
using System.Xml;
-
using System.Xml.Serialization;
-
using System.Xml.Schema;
-
using System.Text;
-
using System.Text.RegularExpressions;
-
using System.IO;
-
-
-
-
namespace WebApplication3
-
{
-
public partial class _Default : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
-
protected void Button1_Click1(object sender, EventArgs e)
-
{
-
-
-
-
//for List 1
-
for (int i = 0; i < ListSecA.Items.Count; i++)
-
{
-
if (ListSecA.Items[i].Selected)
-
{
-
ListSecAValues.Text += ListSecA.Items[i].Value.ToString() + "\n";
-
}
-
}
-
// For List 2
-
for (int x = 0; x < ListSecB.Items.Count; x++)
-
{
-
if (ListSecB.Items[x].Selected)
-
{
-
ListSecBValues.Text += ListSecB.Items[x].Value.ToString() + "\n";
-
}
-
}
-
// For list 3
-
for (int z = 0; z < ListBoxHearAbout.Items.Count; z++)
-
{
-
if (ListBoxHearAbout.Items[z].Selected)
-
{
-
ListHearValues.Text += ListBoxHearAbout.Items[z].Value.ToString() + "\n";
-
}
-
}
-
-
-
-
-
string DetailData = "";
-
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;
-
System.Xml.Serialization.XmlSerializer serializ = new System.Xml.Serialization.XmlSerializer(DetailData.GetType());
-
StringBuilder sb = new StringBuilder();
-
TextWriter writer = new StringWriter(sb);
-
serializ.Serialize(writer, DetailData);
-
-
-
string str = "";
-
SqlConnection conn = new SqlConnection(
-
"Data source=SYED-PC;Initial Catalog=baass;Integrated Security=True");
-
-
conn.Open();
-
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()+ "')";
-
-
-
//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() + "')";
-
-
-
-
SqlCommand md = new SqlCommand(str, conn);
-
-
//int y = md.ExecuteNonQuery();
-
int g = md.ExecuteNonQuery();
-
-
-
conn.Close();
-
MailMessage mails = new MailMessage();
-
-
mails.To = TextBoxEmail.Text;
-
//mails.Bcc = "abcdef@gmail.com";
-
mails.From = "WebRegistration@BAASS.accdoc.com";
-
mails.Subject = "Welcome: " + TextBoxName;
-
-
mails.Body = "Hello " + TextBoxName.Text +
-
"\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):"
-
+ 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):"
-
+ 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):"
-
+ TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text + " \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:"
-
+ 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 "+
-
"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 "+
-
"\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";
-
-
SmtpMail.SmtpServer = "localhost";
-
SmtpMail.Send(mails);
-
-
MailMessage myself = new MailMessage();
-
myself.To = "sshah@baass.com";
-
myself.From = "WebRegistration@BAASS.accdoc.com";
-
myself.Subject = "BAASS Thornhill Online Course Registration Confirmation";
-
myself.Body = "Hello " + TextBoxName.Text +
-
"\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):" + 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):"
-
+ 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):"
-
+ TextBoxName.Text + " \n \n \n Company Name:" + TextBoxCompany.Text +
-
" \n Payment Method:" + DropdownPayment.SelectedItem.Text + " \n Total Amount:" + 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 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 "+
-
"\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 \n \n \n \n ----------------------------------------------------------------------------------- "+
-
"\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):"
-
+ TextBoxName.Text + "\n \n \n Company Name: " + TextBoxCompany.Text + " \n Address 1: " + TextBoxAddress.Text + "Address 2: " + TextBoxAddress2.Text + " \n City: " + TextBoxCity.Text + " \n Province: "
-
+ TextBoxProvince.Text + " \n Postal Code: " + TextBoxPostalCode.Text +
-
" \n Phone Number: " + TextBoxPhone.Text + " \n Fax Number: " + TextBoxFax.Text + " \n Person's Email: " + TextBoxEmail.Text + " \n Website: " + TextBoxWebsite.Text +
-
" \n Number of Attendees: " + TextBoxNumberAtt.Text + " \n \n Series A Course(s):"
-
+ 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: "
-
+ 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: "
-
+ 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 +
-
" \n -----------------------------------------------------------------------------------\n";
-
-
-
SmtpMail.SmtpServer = "Exchange";
-
-
SmtpMail.Send(myself);
-
Response.Redirect("Thanks.aspx");
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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 ...
|
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');
|
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
|
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 ) ;
| |
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:
|
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...
|
by: silambu |
last post by:
hi,can anybody tell reason for getting syntax error near , while either updating or inserting records in table
|
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:...
|
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);
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| | |