• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            Ado.net各種provider的連接直接讀取,填充dataset示例(四)

            直接讀取

            SqlClient

            [Visual Basic]
            Imports System
            Imports System.Data
            Imports System.Data.SqlClient
            Imports Microsoft.VisualBasic
            
            Public Class Sample
            
              Public Shared Sub Main() 
                Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;" & _
                                                                   "Integrated Security=SSPI;Initial Catalog=northwind")
            
                Dim catCMD As SqlCommand = nwindConn.CreateCommand()
                catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories"
            
                nwindConn.Open()
            
                Dim myReader As SqlDataReader = catCMD.ExecuteReader()
            
                Do While myReader.Read()
                  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
                Loop
            
                myReader.Close()
                nwindConn.Close()
              End Sub
            End Class
            [C#]
            using System;
            using System.Data;
            using System.Data.SqlClient;
            
            class Sample
            {
              public static void Main() 
              {
                SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
            
                SqlCommand catCMD = nwindConn.CreateCommand();
                catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories";
            
                nwindConn.Open();
            
                SqlDataReader myReader = catCMD.ExecuteReader();
            
                while (myReader.Read())
                {
                  Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
                }
            
                myReader.Close();
                nwindConn.Close();
              }
            }

            OleDb

            [Visual Basic]
            Imports System
            Imports System.Data
            Imports System.Data.OleDb
            Imports Microsoft.VisualBasic
            
            Public Class Sample
            
              Public Shared Sub Main() 
                Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" & _
                                                                       "Integrated Security=SSPI;Initial Catalog=northwind")
            
                Dim catCMD As OleDbCommand = nwindConn.CreateCommand()
                catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories"
            
                nwindConn.Open()
            
                Dim myReader As OleDbDataReader = catCMD.ExecuteReader()
            
                Do While myReader.Read()
                  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
                Loop
            
                myReader.Close()
                nwindConn.Close()
              End Sub
            End Class
            [C#]
            using System;
            using System.Data;
            using System.Data.OleDb;
            
            class Sample
            {
              public static void Main() 
              {
                OleDbConnection nwindConn = new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
            
                OleDbCommand catCMD = nwindConn.CreateCommand();
                catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories";
            
                nwindConn.Open();
            
                OleDbDataReader myReader = catCMD.ExecuteReader();
            
                while (myReader.Read())
                {
                  Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
                }
            
                myReader.Close();
                nwindConn.Close();
              }
            }

            Odbc

            [Visual Basic]
            Imports System
            Imports System.Data
            Imports System.Data.Odbc
            Imports Microsoft.VisualBasic
            
            Public Class Sample
            
              Public Shared Sub Main() 
                Dim nwindConn As OdbcConnection = New OdbcConnection("Driver={SQL Server};Server=localhost;" & _
                                                                     "Trusted_Connection=yes;Database=northwind")
            
                Dim catCMD As OdbcCommand = new OdbcCommand("SELECT CategoryID, CategoryName FROM Categories", nwindConn)
            
                nwindConn.Open()
            
                Dim myReader As OdbcDataReader = catCMD.ExecuteReader()
            
                Do While myReader.Read()
                  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
                Loop
            
                myReader.Close()
                nwindConn.Close()
              End Sub
            End Class
            [C#]
            using System;
            using System.Data;
            using System.Data.Odbc;
            
            class Sample
            {
              public static void Main() 
              {
                OdbcConnection nwindConn = new OdbcConnection("Driver={SQL Server};Server=localhost;" +
                                                              "Trusted_Connection=yes;Database=northwind");
            
                OdbcCommand catCMD = new OdbcCommand("SELECT CategoryID, CategoryName FROM Categories", nwindConn);
            
                nwindConn.Open();
            
                OdbcDataReader myReader = catCMD.ExecuteReader();
            
                while (myReader.Read())
                {
                  Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
                }
            
                myReader.Close();
                nwindConn.Close();
              }
            }

            OracleClient

            [Visual Basic]
            Imports System
            Imports System.Data
            Imports System.Data.OracleClient
            Imports Microsoft.VisualBasic
            
            Class Sample
            
              Public Shared Sub Main() 
            
                Dim oraConn As OracleConnection = New OracleConnection("Data Source=MyOracleServer;Integrated Security=yes;")
            
                Dim oraCMD As OracleCommand = New OracleCommand("SELECT CUSTOMER_ID, NAME FROM DEMO.CUSTOMER", oraConn)
            
                oraConn.Open()
            
                Dim myReader As OracleDataReader = oraCMD.ExecuteReader()
            
                Do While (myReader.Read())
                  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
                Loop
            
                myReader.Close()
                oraConn.Close()
              End Sub
            End Class
            [C#]
            using System;
            using System.Data;
            using System.Data.OracleClient;
            
            class Sample
            {
              public static void Main() 
              {
                OracleConnection oraConn = new OracleConnection("Data Source=MyOracleServer;Integrated Security=yes;");
            
                OracleCommand oraCMD = new OracleCommand("SELECT CUSTOMER_ID, NAME FROM DEMO.CUSTOMER", oraConn);
            
                oraConn.Open();
            
                OracleDataReader myReader = oraCMD.ExecuteReader();
            
                while (myReader.Read())
                {
                  Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
                }
            
                myReader.Close();
                oraConn.Close();
              }
            }

            填充dataset:

            SqlClient

            [Visual Basic]
            Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")
            
            Dim selectCMD As SqlCommand = New SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn)
            selectCMD.CommandTimeout = 30
            
            Dim custDA As SqlDataAdapter = New SqlDataAdapter
            custDA.SelectCommand = selectCMD
            
            nwindConn.Open()
            
            Dim custDS As DataSet = New DataSet
            custDA.Fill(custDS, "Customers")
            
            nwindConn.Close()
            [C#]
            SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
            
            SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
            selectCMD.CommandTimeout = 30;
            
            SqlDataAdapter custDA = new SqlDataAdapter();
            custDA.SelectCommand = selectCMD;
            
            nwindConn.Open();
            
            DataSet custDS = new DataSet();
            custDA.Fill(custDS, "Customers");
            
            nwindConn.Close();

            OleDb

            [Visual Basic]
            Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" & _
                                                                   "Integrated Security=SSPI;Initial Catalog=northwind")
            
            Dim selectCMD As OleDbCommand = New OleDbCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn)
            selectCMD.CommandTimeout = 30
            
            Dim custDA As OleDbDataAdapter = New OleDbDataAdapter
            custDA.SelectCommand = selectCMD
            
            Dim custDS As DataSet = New DataSet
            custDA.Fill(custDS, "Customers")
            [C#]
            OleDbConnection nwindConn = new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +
                                                            "Integrated Security=SSPI;Initial Catalog=northwind");
            
            OleDbCommand selectCMD = new OleDbCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
            selectCMD.CommandTimeout = 30;
            
            OleDbDataAdapter custDA = new OleDbDataAdapter();
            custDA.SelectCommand = selectCMD;
            
            DataSet custDS = new DataSet();
            custDA.Fill(custDS, "Customers");

            Odbc

            [Visual Basic]
            Dim nwindConn As OdbcConnection = New OdbcConnection("Driver={SQL Server};Server=localhost;" & _
                                                                 "Trusted_Connection=yes;Database=northwind")
            
            Dim selectCMD As OdbcCommand = New OdbcCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn)
            selectCMD.CommandTimeout = 30
            
            Dim custDA As OdbcDataAdapter = New OdbcDataAdapter
            custDA.SelectCommand = selectCMD
            
            nwindConn.Open()
            
            Dim custDS As DataSet = New DataSet
            custDA.Fill(custDS, "Customers")
            
            nwindConn.Close()
            [C#]
            OdbcConnection nwindConn = new OdbcConnection("Driver={SQL Server};Server=localhost;" +
                                                          "Trusted_Connection=yes;Database=northwind");
            
            OdbcCommand selectCMD = new OdbcCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
            selectCMD.CommandTimeout = 30;
            
            OdbcDataAdapter custDA = new OdbcDataAdapter();
            custDA.SelectCommand = selectCMD;
            
            nwindConn.Open();
            
            DataSet custDS = new DataSet();
            custDA.Fill(custDS, "Customers");
            
            nwindConn.Close();



            從多個(gè) DataAdapter 填充 DataSet
            [C#] SqlConnection custConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind;"); SqlDataAdapter custDA = new SqlDataAdapter("SELECT * FROM Customers", custConn); OleDbConnection orderConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\\Program Files\\Microsoft Office\\Office\\Samples\\northwind.mdb;"); OleDbDataAdapter orderDA = new OleDbDataAdapter("SELECT * FROM Orders", orderConn); custConn.Open(); orderConn.Open(); DataSet custDS = new DataSet(); custDA.Fill(custDS, "Customers"); orderDA.Fill(custDS, "Orders"); custConn.Close(); orderConn.Close(); DataRelation custOrderRel = custDS.Relations.Add("CustOrders", custDS.Tables["Customers"].Columns["CustomerID"], custDS.Tables["Orders"].Columns["CustomerID"]); foreach (DataRow pRow in custDS.Tables["Customers"].Rows) { Console.WriteLine(pRow["CustomerID"]); foreach (DataRow cRow in pRow.GetChildRows(custOrderRel)) Console.WriteLine("\t" + cRow["OrderID"]); }

            posted on 2005-11-24 10:33 夢(mèng)在天涯 閱讀(1343) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804603
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            偷偷做久久久久网站| 亚洲国产成人精品91久久久| 色狠狠久久综合网| 久久精品一区二区影院 | 久久人做人爽一区二区三区| 国产—久久香蕉国产线看观看| 精品精品国产自在久久高清| av无码久久久久久不卡网站| 高清免费久久午夜精品| 伊人久久精品线影院| 狠狠人妻久久久久久综合蜜桃| 狠狠综合久久综合中文88| 久久久久亚洲AV综合波多野结衣 | 精品人妻久久久久久888| 久久久久成人精品无码中文字幕 | 久久er热视频在这里精品| 国产精品久久久久久久久鸭| 久久99精品久久久久久9蜜桃| 久久精品这里只有精99品| 久久久国产视频| 亚洲AV日韩精品久久久久| 97精品国产91久久久久久| 国产精品日韩深夜福利久久| 久久天天躁狠狠躁夜夜不卡 | 无码国内精品久久人妻蜜桃| 久久精品视频免费| 一97日本道伊人久久综合影院| 久久无码AV一区二区三区| 国产麻豆精品久久一二三| 久久久精品视频免费观看| 久久久久se色偷偷亚洲精品av| 国产精品久久久久影院嫩草| 久久精品亚洲福利| 精品久久久久中文字幕日本| 久久99精品久久久久久9蜜桃| 中文国产成人精品久久不卡| 久久九九亚洲精品| 亚洲AV成人无码久久精品老人 | 久久国产精品偷99| 久久精品亚洲日本波多野结衣 | 亚洲精品高清久久|