尝试用OLEDB打开EXCEL表读取数据

王朝system·作者佚名  2006-12-17
宽屏版  字体: |||超大  

尝试用OLEDB打开EXCEL表读取数据

尝试用OLEDB打开EXCEL表读取数据 在网上看了很多关对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,悲哀,继续^^^^^

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有