• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

Date as a Parameter for SQL Server query using ASP.NET

I want to insert some data along with the date into SQL Server 2000 using ASP.NET. I have used "DateTime.Now" to get the current local system time using C sharp and then inserted that value in SQL Server.

Now my task is to select some idNumers from the SQL Server . The query looks somewhat like

  select idNumber from  users where UserID=? and Date>=?

I select the parameters "UserID" and "Date" depending on the session userId and date from local system using "DatTime.Now". I used DataSet for this task.

I am getting no rows selected even though there are rows which can satisfy the above query.

How can I add Date as a paramter. Shall I have to do any explicit casting for this.

Plz help me to solve this problem
3 Solutions
Rename the "date" column to be something like "userdate" or something aside from "date" which is a reserved word.
You may want to change the Date column name as said by nan1217 or if not then trying putting Date in square brackets so the query defines the word Date as a field name.

I have also found that the format of the date can make a difference on whether a < or > actually works.  I recommend using the format YYYY/MM/DD so as not to confuse matters on whether it is Euro or US date style.
like already mentioned by dij8, i encounterd big problems with dateformats, too.

for me the following date-format has been the solution - but this format does not work with all configurations, too. if you use it, take care of the "/" and ":" because c# converts these signs to the format your culture-settings fit.

"yyyy/MM/dd HH:mm:ss"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now