Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-25
6
Medium Priority
?
795 Views
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
0
Comment
Question by:partulu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Accepted Solution

by:
nan1217 earned 336 total points
ID: 12405221
Rename the "date" column to be something like "userdate" or something aside from "date" which is a reserved word.
0
 
LVL 10

Assisted Solution

by:dij8
dij8 earned 332 total points
ID: 12406049
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.
0
 
LVL 4

Assisted Solution

by:kolpdc
kolpdc earned 332 total points
ID: 12410359
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"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

604 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