博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用C#来手动连接 Access 2007数据库
阅读量:4691 次
发布时间:2019-06-09

本文共 1333 字,大约阅读时间需要 4 分钟。

  首先新建一个Windows窗体,然后在窗体上拉一个Button控件和一个listbox控件,然后双击Button按钮,再在其双击事件的处理程序中写入其下代码:

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 //引入命名空间10 using System.Data.OleDb;11 12 namespace WindowsFormsApplication113 {14     public partial class Form1 : Form15     {16         public Form1()17         {18             InitializeComponent();19         }20 21         private void button1_Click(object sender, EventArgs e)22         {23             //连接数据库24             OleDbConnection con = new OleDbConnection();25             //在Data Source中写明 Access 2007的文件的路径26             con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\pm\\Desktop\\1.accdb";    29             con.Open();30             OleDbCommand cmd = new OleDbCommand();31             cmd.Connection = con;32             cmd.CommandText = "select * from 1";//1是表名33             OleDbDataReader reader = cmd.ExecuteReader();34             while (reader.Read())35             {36                 listBox1.Items.Add(reader.GetValue(0));37             }38             reader.Close();39             con.Close();40         }41     }42 }

 

转载于:https://www.cnblogs.com/gates/archive/2013/01/19/2868065.html

你可能感兴趣的文章
第一次博客作业
查看>>
第一次个人编程作业
查看>>
第8组 团队展示
查看>>
第一次结对编程作业
查看>>
Redis启停脚本
查看>>
RabbitMQ命令行手动创建队列rabbitmqadmin用法
查看>>
linux修改当前用户环境变量永久生效
查看>>
Javascript Asynchronous Investigation
查看>>
spring学习笔记之---bean管理
查看>>
spring学习笔记之---bean管理的注解方式
查看>>
spring学习笔记之---bean属性注入
查看>>
SpringMVC项目案例之---数据的获取与显示
查看>>
SpringMVC学习笔记之---深入使用
查看>>
SpringMVC学习笔记之---简单入门
查看>>
SpringMVC学习笔记之---数据绑定
查看>>
Mybatis学习笔记之---环境搭建
查看>>
Mybatis学习笔记之---编写dao实现类的CRUD
查看>>
SpringMVC学习笔记之---RESTful风格
查看>>
Mybatis学习笔记之---动态sql中标签的使用
查看>>
Mybatis学习笔记之---CRUD(增删改查)
查看>>