I have an excel file with 1 column, the column contains mixed data,int & string.
After I read the data from the excel file, I saw that the cell with data AZ-965 is null.
this is my string connection
return new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
+ excel + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0;';");
and this how I read data from Excel file
private static List<T> GetImportedData<T>(string sheet, OleDbConnection myConnection,
List<string> column, ImportDataView<T> view) where T : IImportableData
{
var cols = string.Join( ",", column.Select(Cast));
var formattableString = $"select {cols} from [{sheet}$]";
using (var MyCommand = new
OleDbDataAdapter(formattableString, myConnection))
{
using (var DtSet = new DataSet())
{
int nbRow = 0;
MyCommand.Fill(DtSet);
var dt = DtSet.Tables[0];
var rows = dt.AsEnumerable();
var convertedList = rows
//.AsParallel()
.Select(x => GenerateImport<T>(x, column, ref nbRow, view))
.ToList();
return convertedList;
}
}
}
private static string Cast(string arg)
{
return $"IIf(IsNull([{arg}]), '', CStr([{arg}]))";
// return $"CStr([{arg}]) as {cleanName(arg)}";
//return $"[{arg}]";
}
I check this link, but nothing is work, same isue