求高手指点,关于Datagridview的问题
我用Datagridview 现实ACCESS表中的内容。数据库连接如下:
public class db
{
public db()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string connection
{
get
{return"Data Source=123.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;";}
}
}
显示程序如下:
public partial class Form1 : Form
{
private OleDbConnection oleConnection1 = null;
public Form1()
{
InitializeComponent();
this.oleConnection1 = new OleDbConnection(datagrid.database.db.connection);
}
DataSet ds;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
oleConnection1.Open();
string sql = "select A as 姓名,B as 密码 from ss";
OleDbDataAdapter adp = new OleDbDataAdapter(sql, oleConnection1);
ds = new DataSet();
ds.Clear();
adp.Fill(ds, "ss");
dataGridView1.DataSource = ds.Tables["Tss"].DefaultView;
//dataGrid1.CaptionText = "共有" + ds.Tables["person"].Rows.Count + "条记录";
oleConnection1.Close();
}
}
但是就是显示不出来,也没报错。本人初学,请大神帮忙啊!!