oledb连接access数据库示例

时间:2024-01-28 05:54:19 


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand comm = new OleDbCommand();
            OleDbDataReader dr=null;
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Environment.CurrentDirectory + "\\SimpleNews.mdb";
            comm.Connection = conn;
            comm.CommandText = "select * from [login]";
            try
            {
                conn.Open();
                dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    for (int i = 0; i < dr.FieldCount; i++)
                        Console.Write(dr.GetValue(i) + "  ");
                    Console.WriteLine("");
                    //dr.Close();
                }
                dr.Close();
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }
            finally
            {
                comm = null;
                conn.Close();
                comm = null;
                Console.ReadKey();
            }
        }
    }
}

标签:oledb,access数据库
0
投稿

猜你喜欢

  • 一键搞定python连接mysql驱动有关问题(windows版本)

    2024-01-18 05:43:29
  • 卷积神经网络经典模型及其改进点学习汇总

    2023-07-22 22:15:19
  • Keras搭建分类网络平台VGG16 MobileNet ResNet50

    2022-07-28 08:03:51
  • Jupyter notebook无法导入第三方模块的解决方式

    2023-05-23 08:28:53
  • Python pandas RFM模型应用实例详解

    2023-10-15 23:27:34
  • JavaScript对象的property属性详解

    2024-05-05 09:22:57
  • JavaScript前端实用的工具函数封装

    2024-04-25 13:15:02
  • 在go中使用omitempty的代码实例

    2024-04-25 15:12:47
  • python3实现往mysql中插入datetime类型的数据

    2024-01-20 12:45:58
  • Python使用base64模块进行二进制数据编码详解

    2023-08-26 20:13:13
  • python的简单web框架flask快速实现详解

    2023-03-10 08:26:36
  • 使用Python第三方库发送电子邮件的示例代码

    2021-07-24 11:17:36
  • Python实现打乒乓小游戏

    2023-07-20 04:48:53
  • Python实战之手写一个搜索引擎

    2023-07-11 21:16:49
  • TensorFlow 显存使用机制详解

    2022-02-07 11:46:53
  • MySQL 5.7.18 免安装版配置教程

    2024-01-16 06:12:51
  • python3爬虫获取html内容及各属性值的方法

    2021-08-23 02:37:33
  • Mysql临时表及分区表区别详解

    2024-01-23 16:28:00
  • PyQt5 显示超清高分辨率图片的方法

    2021-07-11 04:16:09
  • vue-cli使用stimulsoft.reports.js的详细教程

    2024-04-09 10:58:59
  • asp之家 网络编程 m.aspxhome.com