Note that there are some explanatory texts on larger screens.

plurals
  1. POOleDbConnection Source Variable in C#
    primarykey
    data
    text
    <p>How can I replace <code>D:\temp\test.xls</code> with <code>filePath</code> in <code>OleDbConnection</code> statement. </p> <p>I can get the exactly filePath (with OpenFileDialog, then I can located my .xls file conveniently, no more hardcoded), but when I insert the variable <code>filePath</code> as Style2, it doesn't work. How can I fix this ? Thanks.</p> <p>Style1</p> <pre><code>OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\test.xls;Extended Properties=""Excel 8.0;HDR=Yes;"""); </code></pre> <p>Style2</p> <pre><code>OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=filePath;Extended Properties=""Excel 8.0;HDR=Yes;"""); </code></pre> <p>[Updated] Some part of my code as this,</p> <pre><code>DataTable fooData = new DataTable(); OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=filePath;Extended Properties=""Excel 8.0;HDR=Yes;"""); dbConnection.Open (); try { OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM [maleSheet$]", dbConnection); OleDbDataReader dbReader = dbCommand.ExecuteReader(); int RankIndex = dbReader.GetOrdinal("Rank"); while (dbReader.Read()) { string rank = dbReader.GetValue(RankIndex).ToString(); ////.... } } </code></pre> <p>Error as below at line <code>OleDbDataReader dbReader = dbCommand.ExecuteReader();</code></p> <blockquote> <p>An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload