This is a discussion on "sql data to xml" within the Other Programming Languages section. This forum, and the thread "sql data to xml are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
sql data to xml
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
sql data to xml
Hi all, I'm new to xml.I have a problem when I run the .aspx page. It gives an error message "
System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'XML'. at System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteXmlReader( ) at test.xmlfromsqlsrv.Run() in C:\bf\WEB\RSS\SourceCode\test.cs:line 31 Can anyone help me out. Your help is highly appreciated.Here are the 2 files. .aspx file <%@ Page Language="C#" Debug="true" Src="test.cs"%> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="test" %> <script language="C#" runat="server"> protected void Page_Load(Object Src, EventArgs E) { StringWriter writer = new StringWriter(); Console.SetOut(writer); xmlfromsqlsrv myxmlfromsqlsrv = new xmlfromsqlsrv(); myxmlfromsqlsrv.Run(); output.InnerHtml = writer.ToString(); } </script> <html> <body style="background-color:f6e4c6"> <tr><td><h4><xmp id="output" runat="server"/></h4></td></tr> </body> </html> .cs file namespace test { using System; using System.Data; using System.Data.SqlClient; using System.Xml; public class xmlfromsqlsrv { public static void Main() { xmlfromsqlsrv myxmlfromsqlsrv = new xmlfromsqlsrv(); myxmlfromsqlsrv.Run(); } public void Run() { String sConnection = "Data Source=(local);Initial Catalog=NorthWind;User ID=sa;Password="; SqlConnection mySqlConnection = new SqlConnection(sConnection); SqlCommand mySqlCommand = new SqlCommand("select * from customers FOR XML AUTO, XMLDATA", mySqlConnection); mySqlCommand.CommandTimeout = 15; try { mySqlConnection.Open(); DataSet myDataSet1 = new DataSet(); myDataSet1.ReadXml((XmlTextReader)mySqlCommand.Exe cuteXmlReader(), XmlReadMode.Fragment); myDataSet1.DataSetName = "NewDataSet"; SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from customers", sConnection); DataSet myDataSet2 = new DataSet(); mySqlDataAdapter.Fill(myDataSet2); myDataSet1.WriteXml("data1.xml"); myDataSet2.WriteXml("data2.xml"); Console.WriteLine ("Data has been writen to the output files: data1.xml and data2.xml"); Console.WriteLine (); Console.WriteLine ("********************data1.xml******************* *"); Console.WriteLine (myDataSet1.GetXml()); Console.WriteLine (); Console.WriteLine ("********************data2.xml******************* *"); Console.WriteLine (myDataSet2.GetXml()); } catch(Exception e) { Console.WriteLine(e.ToString()); } finally { mySqlConnection.Close(); } } } } |
|
|
![]() |
| Tags |
| sql, data, xml |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing Data | OmiE | Starting Out | 1 | May 9th, 2007 20:22 |
| Get Data From CSV to MS SQL DB | Brain-Chemical | Databases | 3 | Feb 16th, 2006 06:25 |
| Data Retrival | xbenx | Classic ASP | 0 | Jan 5th, 2006 02:01 |
| Passing Data ... | TheShadow | Classic ASP | 2 | May 30th, 2005 09:31 |
| Data Mining | micah | Classic ASP | 12 | Mar 18th, 2005 14:22 |