Home > Database > Mysql Tutorial > body text

C#读取ACCESS数据

WBOY
Release: 2016-06-07 15:36:25
Original
1682 people have browsed it

// 读取 Access需使用OLEDB using System.Data.OleDb; /// summary /// 读取 Access 数据 库 /// /summary private void ReadAccessData() { // 1、建立连接 string sAccessConnection = @ Provider=Microsoft.Jet.OLEDB.4.0;DataSource=E:\BegVCSharp\Reade

//读取Access需使用OLEDB
usingSystem.Data.OleDb;

 

        /// 

        /// 读取Access数据
        
/// 

        private void ReadAccessData()
        {
            
//1、建立连接

            string sAccessConnection

 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\BegVCSharp\ReaderAccess\ReaderAccess\nwind.mdb";

 

 

            OleDbConnection odcConnection = new OleDbConnection(sAccessConnection);
            
//2、打开连接

            odcConnection.Open();

            
//建立SQL查询

            OleDbCommand odCommand = odcConnection.CreateCommand();
            
//3、输入查询语句

            odCommand.CommandText = "select customerID,companyName from Customers";

            
//建立读取

            OleDbDataReader odrReader = odCommand.ExecuteReader();

            
//查询并显示数据

            while (odrReader.Read())
            {
                
//显示取出值(具体显示方式可由自己定义)

                tbValue.Text += "\r\t";
                tbValue.Text 
+= odrReader["CustomerID"].ToString().PadRight(10' '
);
                tbValue.Text 
+= odrReader["CustomerID"
].ToString();
            }

            
//关闭连接

            odrReader.Close();

            odcConnection.Close();

 

       }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template