C# creation of SQL CE databases

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing an app in C# on a PDA using SQL CE
It is to use British date format : dd/mm/yyyy
I am having problems with the comparison of dates between dates entered in the app and the database
I can format the dates in C# and then format dates using convert in SQL and compare the two.

However , I was wondering is it possible , when programmatically creating a database , to set the region and or date to British format.I would like to ensure that the default formatting for any date field is British
If it's not possible to set the format for the whole database is it possible to specify the format in a create table statement or to add some type of constraint to ensure the date is formatted correctly

Thanks
Den
 
Den said:
I am developing an app in C# on a PDA using SQL CE.
It is to use British date format : dd/mm/yyyy.
I am having problems with the comparison of dates between dates
entered in the app and the database.
I can format the dates in C# and then format dates using convert in
SQL and compare the two..

However , I was wondering is it possible , when programmatically
creating a database , to set the region and or date to British
format.I would like to ensure that the default formatting for any
date field is British.
If it's not possible to set the format for the whole database is it
possible to specify the format in a create table statement or to add
some type of constraint to ensure the date is formatted correctly.

Where are you needing to format the dates in the database anyway? Dates
should just be DateTimes, which are format-less. Send them up in
parameters to avoid any formatting in your SQL, and display them to the
user however you want to. Compare them using straight DateTime
comparisons.
 
Den

If you insist on using dates directly in SQL statements, rather than in parameters, use the method I've included below. It takes a DateTime parameter and wraps it up ready for SQLCE 2.0 to use in INSERT, UPDATE and WHERE clauses

Regard

Liam Westle

public string SafeFieldValue(System.DateTime fieldValue

tr

// universal format, YYYY/MM/DD, solves US versus UK date issue
return "'" + fieldValue.ToString("yyyy/MM/dd HH:mm:ss") + "'"

catc

return ""

}
 
Back
Top