C#连接ACCESS数据库,显示到dataGridView表格
//C#连接ACCESS数据库,显示到dataGridView表格//看有人问,发自己的上来大家参考....................
//*******************************************************************************
using System.Data;
using System.Data.OleDb; //须要引用
private void Form1_Load(object sender, EventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=F:\Projects\Visual Studio 2008\bin\Debug\网费ACCESS.mdb"; //数据库路径
OleDbConnection Conn = new OleDbConnection(strConn);
Conn.Open();
string strSQL = " SELECT * FROM 表1 "; //SQL语句
//创建一个 DataSet
OleDbDataAdapter adp = new OleDbDataAdapter(strSQL, Conn);
DataSet ds= new DataSet();
ds.Clear();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
Conn.Close();
}