Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox Date Validation 2

Status
Not open for further replies.

NerdTop72

Programmer
Mar 14, 2005
117
US
I am using a Text box to gather a Date from a User. I use this information to parse a sql statement for more data. Unfortunately when a user enters a date like
5/5/08

I get a

Syntax error converting datetime from character string.

but when i enter

5/5/2008 it works?
is there anyway when the user clicks off the text box a validation can correct the year to 4 digits to please SQL Server?

Here is my SQL Statement with the syntax error
Code:
SELECT TOP 1 Val FROM FTBL_GritChamber WHERE (TagIndex = '40' OR TagIndex = '39') AND (DateAndTime BETWEEN CONVERT(DATETIME, '5/5/08 2:03:00 PM', 102) AND CONVERT(DATETIME, '5/5/08 2:23:00 PM', 102))
To correct the syntax error the date just needs to be 2008? since looking into data validation, all I can come up with is a date compare? I do not see how this will help me in my situation?

Thanks
 
use a date control, rather than a basic textbox.
there are plenty out there. MS AJAX toolkit includes one. BasicDatePicker offers both a free and $ version. I'm sure you could also find some jquery plugins which would convert a textbox to a calendar as well.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
You shouldn't assume 08 = 2008. You can use a calendar control to have the user pick the date, or use a validator control and force the user to enter it correctly.
 
Thanks,
I didn't want to do it that way because it would mess up my table I made because of how big it grows making it visible on 1 screen. I have lot's of inputs.
 
If that is the case, you can use have an icon next to the textbox. And when clicked, pops open a window(using js) with a calendar control on it. Then send that value back to the textbox and close the window(js)
 
Thanks Jbeson001,
more stuff for my weekend :) ...(js)

is there an easy Web Developer 20088 Wizard driven tool to create a js popup screen on the fly with little coding?

hahaha

Jason #2
 
nope. You will have to write it yourself. The good news is it isn't hard even if you don't know js. And there are plenty of examples on-line. Start off by looking at the window.open() method in js.
 
I have lot's of inputs.
this will become a problem. you should look into using a wizard (either the asp.net wizard, or some form of your own) to manage the number of visible inputs per screen.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top