zoukankan      html  css  js  c++  java
  • c# 读取Access数据库资料

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

            /// <summary>

            /// 读取Access数据库
            
    /// </summary>
            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();

           }

  • 相关阅读:
    对List进行子查询及分组
    网格数据库架构设计构想
    推荐一款简单实用的漏洞测试工具:Paros
    用友U9产品SOA设计架构遭技术质疑
    超简单使用MemCached
    不按常规出招
    如何学好AJax、求高手指点
    Begin
    SpringBoot基础
    SpringBoot基础学习(番外9.1)Spring MVC或Spring Boot配置默认访问页面不生效?
  • 原文地址:https://www.cnblogs.com/scottckt/p/1263262.html
Copyright © 2011-2022 走看看