打印本文 打印本文 关闭窗口 关闭窗口
ADO.NET最佳实践(上)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2733  更新时间:2009/4/23 10:49:22  文章录入:mintao  责任编辑:mintao
er("SELECT * FROM Customers", nwindConn)

    custDA.Fill(myDataSet, "Customers")

    Dim ordersDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Orders", nwindConn)

    ordersDA.Fill(myDataSet, "Orders")

    nwindConn.Close()

    myDataSet.Relations.Add("CustOrders",_                            myDataSet.Tables("Customers").Columns("CustomerID"),_                            myDataSet.Tables("Orders").Columns("CustomerID")).Nested = true

    Dim xmlDoc As XmlDataDocument = New XmlDataDocument(myDataSet)

    Dim xslTran As XslTransform = New XslTransform

    xslTran.Load("transform.xsl")

    Dim writer As XmlTextWriter = New XmlTextWriter("xslt_output.html", System.Text.Encoding.UTF8)

    xslTran.Transform(xmlDoc, Nothing, writer)

    writer.Close()

  End Sub

End Class

‘C#

using System;

using System.Data;

using System.Data.SqlClient;

using System.Xml;

using System.Xml.Xsl;

public class Sample

{

  public static void Main()

  {

    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Initial Catalog=northwind;Integrated Security=SSPI;");

    nwindConn.Open();

    DataSet custDS = new DataSet("CustomerDataSet");

    SqlDataAdapter custDA = new SqlDataAdapter("SELECT * FROM Customers", nwindConn);

    custDA.Fill(custDS, "Customers");

    SqlDataAdapter ordersDA = new SqlDataAdapter("SELECT * FROM Orders", nwindConn);

    ordersDA.Fill(custDS, "Orders");

    nwindConn.Close();

    custDS.Relations.Add("CustOrders",

                         custDS.Tables["Customers"].Columns["CustomerID"],

                         custDS.Tables["Orders"].Columns["CustomerID"]).Nested = true;

    XmlDataDocument xmlDoc = new XmlDataDocument(custDS);

    XslTransform xslTran = new XslTransform();

    xslTran.Load("transform.xsl");

    XmlTextWriter writer = new XmlTextWriter("xslt_output.html", System.Text.Encoding.UTF8);

    xslTran.Transform(xmlDoc, null, writer);

    writer.Close();

  }

}

ADO.NET最佳实践(中)

http://www.csdn.net/Develop/read_article.asp?id=22663

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口