You can set the cell format in Excel.
If the format is different from the format of the input data, the data cannot be read.
For example, I have set the format of a cell column to date.
If the data I entered is indeed in the date format, such as 2002-1-1 1, it can be correctly read.
However, if the data I input is not in the date format, it is a letter like abc or another
In this case, the read data is empty.
Code for reading Excel files
OleDbConnection objConn = null;
DataSet data = new DataSet ();
Try
{
String strConn = "Provider = Microsoft. Jet. OleDb.4.0;" + "data source =" + Path + "; Extended Properties = Excel 8.0 ;";
ObjConn = new OleDbConnection (strConn );
ObjConn. Open ();
DataTable schemaTable = objConn. GetOleDbSchemaTable (System. Data. OleDb. OleDbSchemaGuid. Tables, null );
String tableName = schemaTable. Rows [0] [2]. ToString (). Trim ();
String strSql = "Select * From [" + tableName + "]";
OleDbCommand objCmd = new OleDbCommand (strSql, objConn );
OleDbDataAdapter sqlada = new OleDbDataAdapter ();
Sqlada. SelectCommand = objCmd;
Sqlada. Fill (data, "BuyPrice ");
ObjConn. Close ();
}
Catch
{
ObjConn. Close ();
Throw;
}
Return data;