小弟的代码如下, 但在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["订单表"];
}
环境: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["订单表"];
}
有32位和64位2个版本的,在VS里面,只能是32位版本的 Microsoft Access Database Engine ,安装64位的也不行发布之后可以是64位的
http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=c06b8369-60dd-4b64-a44b-84b371ede16d
但就是gridview无法显示。不知道是不是程序写的有问题,或者是DataSet里面根本就没获得数据。
麻烦再给看看,是不是程序的问题。
你看你的
path = System.IO.Directory.GetCurrentDirectory() + "\\ERP.accdb";
得到的是什么,自己打开看里面有数据吗
InitConnOpen()执行了吗cmd.Fill(ds, "订单表");
之后看看MessageBox.Show(ds.Tables.Count.ToString()) 是多少,然后在for(i=0;i<ds.Tables.Count;i++)
MessageBox.Show(ds.Tables[i].Rows.Count.ToString())看看是否都大于0
在debug模式下
显示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”。应该是64,32位的问题
release之后,数据库可能都覆盖了。可能是空表
MessageBox.Show(ds.Tables[i].Rows.Count.ToString())
这个是显示有多少行?我想显示每一行的内容应该用什么?