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

Posted on 2004-10-25
Last Modified: 2008-01-09
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
Question by:partulu
    LVL 3

    Accepted Solution

    Rename the "date" column to be something like "userdate" or something aside from "date" which is a reserved word.
    LVL 10

    Assisted Solution

    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.
    LVL 4

    Assisted Solution

    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"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Suggested Solutions

    The first time you look at a web page and its source code, you are probably a little intimidated by the use of symbols and jargon that really looks foreign to you. You might not even know where to start to begin learning what it all means. That’…
    Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to dynamically set the form action using jQuery.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now