Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm writing values to excel as follows
C#
OleDbConnection excelConnection = null;
excelConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + location + ";Mode=ReadWrite;Extended Properties=Excel 8.0;");
excelConnection.Open();

OleDbCommand cmd = new OleDbCommand(createCommand, excelConnection);
cmd.ExecuteNonQuery();


Then I create Insert command and insert records to excel sheet.
C#
insertCommand.ExecuteNonQuery();


But when I insert Date value with the format of "yyy.mm.dd" it writes date with the current regional language format to the excel.

Is there any way to set date format in excel using OleDbCommand
Posted

I don't think there is a solution for it.
It is a good thing that Excel uses the current regional settings for the date format. Excel documents can be from computers using different regional settings without any problem.

When you're sure you want to store a date in a specific regional format best use a String data type for it.

Piet
 
Share this answer
 
Excel converts value fields like Number/Date etc to the appropriate format set on the machine. On changing the system culture, we can change the format; not sure about OleDB code.
 
Share this answer
 
Comments
pietvredeveld 21-Feb-12 8:02am    
When you change the system culture of the culture of the current thread, OleDB will use that culture. In my understanding the requirement is to store in another culture than the current. That can not been achieved as far as I know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900