I am reading Excel file by using OLEDBConnection in C#.
I want to change current thread culture as per culture of Excel file so I can get dates in culture specific formats. I have used following code but it is not working. It still converts date to us English format. If I change Format from Control Panel --> Region and Language
then it works:
My Code:
public static System.Data.DataTable GetWorksheet(string worksheetName, string connectionString)
{
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ", true);
Thread.CurrentThread.CurrentCulture.ClearCachedData();
OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter(
//"select * from [" + worksheetName + "]", con);
"select * from [" + worksheetName + "$]", con);
con.Open();
System.Data.DataSet excelDataSet = new DataSet();
cmd.Fill(excelDataSet);
con.Close();
con.Dispose();
System.Data.DataTable dt = excelDataSet.Tables[0];
if (excelDataSet != null)
excelDataSet.Dispose();
return dt;
}
catch (Exception e)
{
throw e;
}
}