DataGridView 绑定Access 2007 数据库问题。
小弟的代码如下, 但在datagridview中无法显示数据库的内容,请各位大侠指点一下。
环境:Win7 + VS2008 + Access 2007
目前的代码在release模式下可以运行,但无法显示数据库内容, 在debug模式下
显示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”。
private string path = System.IO.Directory.GetCurrentDirectory() + "\\ERP.accdb";
private OleDbConnection conn;
private OleDbDataAdapter cmd;
private DataSet ds;
private void InitConnOpen()
{
if (conn == null)
conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + path + ";Persist Security Info=False");
if (conn.State == ConnectionState.Closed)
conn.Open();
cmd = new OleDbDataAdapter("select 客户名称 from [订单表]", conn);
ds = new DataSet();
cmd.Fill(ds, "订单表");
}
private void InitDataGridView()
{
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToOrderColumns = true;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.MultiSelect = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
DataGridViewTextBoxColumn colindex = new DataGridViewTextBoxColumn();
colindex.DataPropertyName = "index";
colindex.HeaderText = "客户名称";
colindex.Name = "客户名称";
colindex.Width = 80;
colindex.SortMode = DataGridViewColumnSortMode.NotSortable;
dataGridView1.Columns.Add(colindex);
this.dataGridView1.DataSource = ds.Tables["订单表"];
}