SQL Datetime - Independent Format
-
A big problem is a Datetime object in the CommandText property. I always get an error. Is .NET unable to convert Datetime object into the right SQL Server system format? When it's possible ... how to solve it?
Seraphin wrote: A big problem is a Datetime object in the CommandText property. Why are you putting a DateTime in the CommandText property? Seraphin wrote: Is .NET unable to convert Datetime object into the right SQL Server system format? .NET is perfectly capbable of converting a DateTime object to what ever format you wish in multiple calendars (should you so wish it). Seraphin wrote: how to solve it? If you need to use a DataTime (or anything else for that matter) in a query you should use parameters. This reduces the possibility of security holes.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE SomeDate > @theDate";
cmd.Parameters.Add("@theDate", myDateTimeObject);Does this help?
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
-
Seraphin wrote: A big problem is a Datetime object in the CommandText property. Why are you putting a DateTime in the CommandText property? Seraphin wrote: Is .NET unable to convert Datetime object into the right SQL Server system format? .NET is perfectly capbable of converting a DateTime object to what ever format you wish in multiple calendars (should you so wish it). Seraphin wrote: how to solve it? If you need to use a DataTime (or anything else for that matter) in a query you should use parameters. This reduces the possibility of security holes.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE SomeDate > @theDate";
cmd.Parameters.Add("@theDate", myDateTimeObject);Does this help?
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More