I want read the table name " check " in sheet 2 but it always show error missing operator. How can i fix it.
Here is my code
public DataTable ReadExcel(string fileName, string fileExt)
{
string conn = string.Empty;
DataTable dtexcel = new DataTable();
if (fileExt.CompareTo(".xls") == 0)
conn = @"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HRD=Yes;IMEX=1';";
else
conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1';";
using (OleDbConnection con = new OleDbConnection(conn))
{
try
{
OleDbDataAdapter oleAdpt = new OleDbDataAdapter("select Check * from [Sheet2$] ", con);
oleAdpt.Fill(dtexcel);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
return dtexcel;
}

Salman BegRank #284 · 8.8K reputationPosted Jun 6, 2021, 10:47 PM EDT
Leon DRank #851 · 2.6K reputationPosted Jun 7, 2021, 9:01 PM EDT
You can use Free Spire.XLS nuget package (https://www.nuget.org/packages/FreeSpire.XLS/) to easily read excel worksheet to datatable.