The 0utput lala.xml
<*Library>You need this code:
<*Book id="1">
<*Name>Programming
<*Author>L.L Yee
<*Book id="2">
<*Name>Mathematics
<*Author>Jason Lee
<*/Library>
using System;
using System.Collections.Generic;
using
System.Text;
using System.Data.SqlClient;
using
System.Configuration;
using System.Xml;
namespace TobyXML
{
class
Program
{
static void Main(string[]
args)
{
ReadCustomerFromDB();
}
public static void
ReadCustomerFromDB()
{
string sql = "Select * from library";
string
output = "";
using (SqlConnection myConnection =
new
SqlConnection(ConfigurationManager.ConnectionStrings["lala"].ConnectionString))
{
myConnection.Open();
SqlCommand
mySqlCommand = new SqlCommand(sql, myConnection);
SqlDataReader datareader =
mySqlCommand.ExecuteReader();
XmlDocument xmlDoc = new
XmlDocument();
xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
XmlNode
nodeLibrary =
xmlDoc.CreateElement("Library");
xmlDoc.AppendChild(nodeLibrary);
while(datareader.Read())
{
XmlNode
nodeBook = xmlDoc.CreateElement("Book");
XmlAttribute attId =
xmlDoc.CreateAttribute("id");
attId.Value =
datareader["bookid"].ToString();
nodeBook.Attributes.Append(attId);
XmlNode
nodeName =
xmlDoc.CreateElement("Name");
nodeName.AppendChild(xmlDoc.CreateTextNode(datareader["bookName"].ToString()));
nodeBook.AppendChild(nodeName);
XmlNode
nodeAuthor =
xmlDoc.CreateElement("Author");
nodeBook.AppendChild(nodeAuthor);
nodeAuthor.AppendChild(xmlDoc.CreateTextNode(datareader["author"].ToString()));
nodeLibrary.AppendChild(nodeBook);
}
datareader.Close();
xmlDoc.Save(@"c:\lala.xml");
}
}
}
}
12 comments:
Thanks for the demo. Any chance you can post the lala ConnectionString
I afraid that I lost it. Do you have any problem using this code?
Buy Generic Medications Here. Order Generic Medication In own Pharmacy. Buy Pills Central.
[url=http://buypillscentral.com/buy-generic-tamiflu-online.html]Buy Top Quality Viagra, Cialis, Levitra, Tamiflu[/url]. canadian generic drugs. Discount pills pharmacy
As a replacement for many years Buy off Viagra Diminish Dispensary has been recognizable all of a add up to leading online apothecary suppliers and customers nearly generic Viagra now the world.
Hello!!! carso-owen.blogspot.com is one of the most excellent innovative websites of its kind. I take advantage of reading it every day. carso-owen.blogspot.com rocks!
The author of carso-owen.blogspot.com has written an excellent article. You have made your point and there is not much to argue about. It is like the following universal truth that you can not argue with: Artificial grape and banana are delicious. Thanks for the info.
http://markonzo.edu http://www.netknowledgenow.com/members/ativan-side-effects.aspx http://blog.bakililar.az/valtrex/ http://www.netknowledgenow.com/members/lorazepam-side-effects.aspx organ
carso-owen.blogspot.com is the best. Thank your for this article. I enjoyed it very much.
AAA Toronto Payday Loans 1172 Bay St #101, Toronto, ON M5S 2B4 (416) 477-2817
Also that we would do without your brilliant phrase
Very usefull
Thanks!
Hi
Thanks your article helps me a lot.
Anuj
Arejealiw [url=http://bit.ly/elancreditcard]elan credit card[/url] erdsyk
Post a Comment