Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I can import a Excel sheet to an DataSet with an OleDb connection.
For example with this code:

string connstr ="Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\aaa.xls;Extended Properties=Excel 8.0"/>
       OleDbConnection conn = new OleDbConnection(connstr);
       string strSQL = "SELECT * FROM [Sheet$]";

       OleDbCommand cmd = new OleDbCommand(strSQL, conn);
       DataSet ds = new DataSet();
       OleDbDataAdapter da = new OleDbDataAdapter(cmd);
       da.Fill(ds);


But when I try to import from a sheet in VSTO Workbook the workbook is already open and so I get an error.
Does anyone has an Example how I can import to a Dataset from a VSTO Workbook.
(The sheet that I want to export to a DataSet a member of the VSTO workbook)

Thanks
Chris
Posted

Take a look at the links provided in the answer to this[^] thread on MSDN.Social.
 
Share this answer
 
Hi,

now I don't get an error, but nothing is in the dataset. Here's my code:
string strWorkbookName = Globals.ThisWorkbook.FullName;
            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strWorkbookName + ";Extended Properties='Excel 12.0;HDR=Yes'";
            OleDbConnection xlConn = new OleDbConnection(strConn);
            string strExcelSheet = Globals.Tabelle1.Name;
            Properties='Excel 8.0;HDR=Yes;IMEX=1'";
            OleDbDataAdapter xlDA = new OleDbDataAdapter("Select * from [" + strExcelSheet + "$] ", xlConn);
            xlDA.Fill(dsDataLoad, "dtDLD");
            MessageBox.Show(dtDLD.Rows[7]["colSAPCode"].ToString());
            dataGridView1.DataSource = dtDLD;


Anyone knows what's wrong here
Thanks Chris
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900