在网上看了很多关对EXCEL文件数据的操作,大部分都是关于COM对EXCEL的操作,如果采用OLEDB将EXCEL当一数据库来操行,那么实现如何??
string strXls = this.textBoxXls.Text.Trim();
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strXls +
"Book7.xls;Extended Properties=Excel 8.0;");
conn.Open();
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from [cnMarc]";
System.Data.OleDb.OleDbDataReader dr = cmd.ExecuteReader();;
while(dr.Read())
{
MessageBox.Show(dr["Title"].ToString());
}
dr.Close();
conn.Close();
}
catch(Exception err)
{
MessageBox.Show(err.Message.ToString());
}
注:上文程序在调试时没有通过.报数据库引擎打到表cnMarc,悲哀,继续^^^^^