private void BtSelectOutputdata_Click(object sender, EventArgs e) /*查询按钮*/
{
string source ="Provider=Microsoft.Jet.OleDb.4.0;" + "data source=E:\\MyProgram\\CsAccess\\ConnectAccess\\data.mdb";
using(OleDbConnection conn =new OleDbConnection(source))
{
conn.Open();
/*用DataReader来填充DataTable*/
string select = @"select * from result";
OleDbCommand cmd = new OleDbCommand(select,conn);
OleDbDataReader reader = cmd.ExecuteReader(); /*创建一个reader*/
DataTable TSelectReSoult = new DataTable(); /*存放要在Gridview里面显示的最后结果*/
TSelectReSoult.Load(reader); /*就这一句用DataTable.Load(DataReader)来把查询到的数据插入到DataTable中*/
reader.Close(); /*记得用完要关闭reader*/
dataGridView1.DataSource=TSelectReSoult;
conn.Close();
}
}
阅读(17816) | 评论(0) | 转发(0) |