Mondeo Posted August 16, 2007 Posted August 16, 2007 I have this statement SELECT * FROM vwAllMatrixVehicles WHERE created >= '2007/8/9' Using query analyser in sql management studio it returns about 80 rows. Trying to use it in ASP.NET with the SqlCommand class the same statement returns 0 rows. I've double checked my code, its fine. If I replace the select statement with something else that doesn't use a date its fine. Does SqlClient handle dates differently somehow? Thanks Quote
Administrators PlausiblyDamp Posted August 16, 2007 Administrators Posted August 16, 2007 It's probably down to the date format being interpreted differently between ASP.Net and SQL Management studio. Try putting the month as a full string (i.e. either August or September depending) and see if that alters the results. Also how is the string being generated in the ASP.Net page? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mondeo Posted August 16, 2007 Author Posted August 16, 2007 Originally I was just building the string with concatenation, but for this example I just put it directly into a string Dim sql as string = "SELECT * FROM vwAllMatrixVehicles WHERE created >= '2007/8/9'" Its very puzzling??? Quote
Administrators PlausiblyDamp Posted August 16, 2007 Administrators Posted August 16, 2007 What do you get if you tru [highlight=sql] Dim sql as string = "SELECT * FROM vwAllMatrixVehicles WHERE created >= '2007/9/8'" [/highlight] Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mondeo Posted August 17, 2007 Author Posted August 17, 2007 Spot on. If I reverse the month and day it works fine. SqlClient must split the string up and pass the values individually, perhaps as parameters. Thanks a lot Quote
Administrators PlausiblyDamp Posted August 17, 2007 Administrators Posted August 17, 2007 Rather than concatenating strings use a parameterized query - that way you don't need to worry about different systems trying to interpret the strings correctly. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.