Click here to Skip to main content
15,909,030 members
Home / Discussions / C#
   

C#

 
GeneralRe: DateTime Pin
Luis Alonso Ramos14-May-05 17:13
Luis Alonso Ramos14-May-05 17:13 
If you want to store a date in SQL server, use parametized queeries, and that'll solve the problem, in any format SQL Server uses.
DateTime myDateTime = .....
string sql = "UPDATE People SET BirthDate = @Date WHERE ID_person = 1";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Date", myDateTime);
cmd.ExecuteNonQuery();
That will save the correct date, no matter what format is the local computer, and/or SQL Server's computer using.

Alternatively, there's a way to change the date format for SQL Server, but I don't remember the exact syntax. Using parametized queries, I don't need it.

Also, parametized queries help avoid SQL injection attacks, so I'll recommend them for every circumstance.

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: DateTime Pin
pubududilena15-May-05 18:15
pubududilena15-May-05 18:15 
GeneralNewbie: Q regarding Sorting DataGrid Pin
nad226314-May-05 8:36
nad226314-May-05 8:36 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
MoustafaS14-May-05 14:41
MoustafaS14-May-05 14:41 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
nad226314-May-05 18:21
nad226314-May-05 18:21 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
Gary Perkin17-May-05 5:58
Gary Perkin17-May-05 5:58 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
nad226318-May-05 10:39
nad226318-May-05 10:39 
Generali have the same problem also Pin
snouto14-May-05 8:00
snouto14-May-05 8:00 
GeneralRe: i have the same problem also Pin
Polis Pilavas14-May-05 8:10
Polis Pilavas14-May-05 8:10 
GeneralSmall question Pin
snouto14-May-05 7:42
snouto14-May-05 7:42 
GeneralRe: Small question Pin
Polis Pilavas14-May-05 8:01
Polis Pilavas14-May-05 8:01 
GeneralRe: Small question Pin
snouto14-May-05 8:11
snouto14-May-05 8:11 
GeneralRe: Small question Pin
Polis Pilavas14-May-05 8:14
Polis Pilavas14-May-05 8:14 
GeneralRe: Small question Pin
snouto14-May-05 8:19
snouto14-May-05 8:19 
GeneralRe: Small question Pin
MoustafaS14-May-05 10:28
MoustafaS14-May-05 10:28 
GeneralRe: Small question Pin
mav.northwind14-May-05 20:25
mav.northwind14-May-05 20:25 
GeneralRe: Small question Pin
lgstef16-May-05 1:31
lgstef16-May-05 1:31 
GeneralAsynchronous file transfer client/server Pin
methodincharge14-May-05 7:37
methodincharge14-May-05 7:37 
GeneralRe: Asynchronous file transfer client/server Pin
snouto14-May-05 7:49
snouto14-May-05 7:49 
GeneralCatching event before file opens Pin
krisst_k14-May-05 3:43
krisst_k14-May-05 3:43 
GeneralRe: Catching event before file opens Pin
MoustafaS14-May-05 7:10
MoustafaS14-May-05 7:10 
GeneralRe: Catching event before file opens Pin
krisst_k14-May-05 14:23
krisst_k14-May-05 14:23 
GeneralRe: Catching event before file opens Pin
Dave Kreskowiak15-May-05 5:51
mveDave Kreskowiak15-May-05 5:51 
GeneralPerformanceCounter Problem Pin
Zishan Haider14-May-05 3:23
Zishan Haider14-May-05 3:23 
GeneralDatabase WebService Pin
Yeast2714-May-05 2:49
Yeast2714-May-05 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.