阅读Excel Sheet使用OleDb [英] Reading from Excel Sheet usng OleDb

查看:55
本文介绍了阅读Excel Sheet使用OleDb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一张excel表格,它以XML的形式保存测试结果。当我在excel中打开工作簿时,要求选择Open作为xml表。



我编写了使用OleDb提供程序从同一个excel表中检索记录的代码ADO.Net。下面是代码。



Hi,

I have an excel sheet which holds the test results in the form of XML. When I open the workbook in excel, asks to select Open as an xml table.

I have written the code for retrieving the records from the same excel sheet using OleDb provider of ADO.Net. Below is the Code.

OleDbConnection objConnection = new OleDbConnection();

                    string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ strSourcePath + "\\" + row.Cells[2].Value.ToString() + ".xls" + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"";
                    objConnection.ConnectionString = con;

 

                    OleDbCommand objCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", objConnection);
                    OleDbDataAdapter da = new OleDbDataAdapter(objCommand);

                    DataSet ds = new DataSet();

                    da.Fill(ds);

                    dataGridView2.DataSource = ds.Tables[0];





抛出OleDbException,外部表不是预期的格式。当Fill metod被调用时。



请为此建议解决方案。



谢谢&此致,

Raghuveer



It is throwing an OleDbException, "External table is not in the expected format." when the Fill metod is called.

Please suggest a resolution for this.

Thanks & Regards,
Raghuveer

推荐答案

,objConnection);
OleDbDataAdapter da = new OleDbDataAdapter(objCommand);

DataSet ds = new DataSet();

da.Fill(ds);

dataGridView2.DataSource = ds.Tables [ 0 ];
", objConnection); OleDbDataAdapter da = new OleDbDataAdapter(objCommand); DataSet ds = new DataSet(); da.Fill(ds); dataGridView2.DataSource = ds.Tables[0];

< br $>


当调用Fill metod时,抛出OleDbException,外部表格不是预期的格式。



请为此建议解决方案。



谢谢和问候,

Raghuveer



It is throwing an OleDbException, "External table is not in the expected format." when the Fill metod is called.

Please suggest a resolution for this.

Thanks & Regards,
Raghuveer


这篇关于阅读Excel Sheet使用OleDb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆