连接access的语句

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace accesslink
{
public partial class Form1 : Form
{
OleDbConnection objConnection;
DataSet myds;
int vrec;
public Form1()
{
InitializeComponent();
}
private void linkdb()
{
string s = "Provider=Microsoft.Jet.oledb.4.0;data source=Student.mdb";
objConnection = new OleDbConnection(s);
objConnection.Open();
}

private void button1_Click(object sender, EventArgs e)
{
linkdb();
string sql = "select * from 基本信息表";
OleDbDataAdapter mydata = new OleDbDataAdapter(sql, objConnection);
DataSet myds=new DataSet();
vrec = mydata.Fill(myds, "基本信息表");
dataGridView1.DataSource = myds.Tables["基本信息表"];
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

原文地址:https://www.cnblogs.com/zhaoshunjie/p/3764668.html