i have sqlCE DataBase, i have Tdate field (datetime)
i notice that his format is: MM/DD/YYYY
in my C# program i work with date in: DD/MM/YYYY format.
how i can insert to my sqlCE data base my C# format ?
i have sqlCE DataBase, i have Tdate field (datetime)
i notice that his format is: MM/DD/YYYY
in my C# program i work with date in: DD/MM/YYYY format.
how i can insert to my sqlCE data base my C# format ?
Maybe there's some function, i'm not sure. My variant is:
string DateString = "25/10/2009";
DateTime dateTime = DateTime.Parse(DateString);
string sqlString = datetime.Month+"/"+dateTime.Day+"/"+dateTime.Year;
i have Tdate field (datetime) i notice that his format is: MM/DD/YYYY
No, the datetime field doesn't have any format. The format is determined when the datetime value is converted into a string after reading it from the database.
The same works when you insert a datetime value in the database, you use a datetime value, not a string. If you supply a string value to the database, it will try to parse it into a datetime value. Whatever format you use when you insert the datetime value, that doesn't affect how the value is returned when you read it, as only the value is stored in the database not the format.
When you insert the value you should use a parametererized query so that you supply the date as a DateTime value, not as a formatted string in the query.
When you read the data from the database, you get a DateTime value. You can either set the culture of the application to control how the default conversion from DateTime to string is done, or use a specific culture or format when you convert it.