sql data to xml

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > Other Programming Languages

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 18th, 2006, 17:39
New Member
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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();
}
}
}
}
Reply With Quote

Reply

Tags
sql, data, xml

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 03:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43