DataGridView提不出数据?
很简单的,代码如下:
private void button1_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = this.openFileDialog1.FileName;
this.textBox1.Text = fileName;
this.ConnAccess(fileName);
}
}
public void ConnAccess(string fileName) //连接access
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = string.Format(@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + @ "{0};User ID=admin;Password=; ", fileName);
conn.Open();
System.Data.OleDb.OleDbCommand comm = new OleDbCommand ( "select * from 登记 ");
comm.Connection = conn;
DataSet ds = new DataSet ();
System.Data.OleDb.OleDbDataAdapter myda = new OleDbDataAdapter();
myda.SelectCommand = comm;
myda.Fill(ds);
this.dataGridView1.DataSource = ds ;
}
// 执行后,DataGridView没有数据,数据库如果为空的话,应该显示字段名啊,连字段名都没有,
程序单点调试全都过,一点问题没有,不知道哪里错了?
以前一直弄B/S来着,C/S都快忘差不多了,大家帮帮忙,小M先谢了~~~~
------解决方案--------------------this.dataGridView1.DataSource = ds.ables[0];
------解决方案--------------------ds.tables[0]