• <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++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            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();



            從多個 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 夢在天涯 閱讀(1345) 評論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807518
            • 排名 - 5

            最新評論

            閱讀排行榜

            99久久成人国产精品免费| 亚洲国产精品综合久久一线| 国内精品人妻无码久久久影院导航| 性做久久久久久久久老女人| 久久久久人妻一区二区三区| 亚洲AV无码久久精品成人| 国产激情久久久久影院老熟女免费| 精品无码人妻久久久久久| 精品久久亚洲中文无码| 国产精品久久久久久一区二区三区| 亚洲国产成人精品无码久久久久久综合 | 97久久香蕉国产线看观看| 亚洲狠狠综合久久| 色综合久久久久无码专区| 久久996热精品xxxx| 久久国产精品成人片免费| 久久露脸国产精品| 久久福利青草精品资源站| 亚洲综合伊人久久综合| 亚洲国产精品综合久久一线| 99久久综合国产精品二区| 国产精品久久久久AV福利动漫| 思思久久99热只有频精品66| 国产AV影片久久久久久 | 理论片午午伦夜理片久久| 99999久久久久久亚洲| 亚洲va久久久噜噜噜久久狠狠 | 人妻丰满AV无码久久不卡| 色综合久久中文字幕综合网| 国产视频久久| 狠狠综合久久综合中文88| 情人伊人久久综合亚洲| 99精品久久精品| 国产精品9999久久久久| 久久久精品2019免费观看| 无码国内精品久久人妻蜜桃| 日韩乱码人妻无码中文字幕久久| 久久受www免费人成_看片中文| 久久噜噜久久久精品66| 亚洲日本久久久午夜精品| 久久天天躁狠狠躁夜夜avapp|