日期:2014-05-18 浏览次数:20848 次
void OpenFile(string fileName) { //创建数据库连接 string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName; OleDbConnection aConnection = new OleDbConnection(strconn); //创建command对象并保存sql查询语句 OleDbCommand aCommand = new OleDbCommand("select * from GeoXY", aConnection); try { aConnection.Open(); //创建datareader 对象来连接到表单 OleDbDataReader aReader = aCommand.ExecuteReader(); //循环遍历数据库 while (aReader.Read()) { ..... } aReader.Close(); aConnection.Close(); } catch(OleDbException e) { MessageBox.Show(e.Message); } }