473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Date time control

Hi,

I have a web form and this form takes a date data from user and stores
it to database (SQL). I written a store procedure to perform this but
when I do not fill the date textbox, SQL gives an error message about
filling the date textbox. In SQL I checked "accept null" for the date
column. What can I do?

Thanks.
Nov 18 '05 #1
1 1056
When you do something like this:

cmd.Parameters.Add("@DateName", txtDateBox.Text);

you will end up with String.Empty as a value many times. There are a couple
of ways to handle this, but here is my suggestion (or something similar as I
am shooting from the hip here):

SqlDateTime dt;

if(txtDateBox.Text.Trim() == String.Empty)
dt = SqlDateTime.Null;
else
dt = new SqlDateTime(Convert.ToDateTime(txtDateBox.Text));

You will likely want to validate the date first, as some entering
"asjdflksajdlf" into the textbox with throw an exception, but this idea
should get you started.

Rule #1: Never trust user input
Rule #2: Be explicit (in this case casting to a SqlType is safest)

NOTE: This assumes SQL Server. For other tproviders, use the correct
datatypes.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Baris - Izmir" <re******@yahoo.com> wrote in message
news:1f**************************@posting.google.c om...
Hi,

I have a web form and this form takes a date data from user and stores
it to database (SQL). I written a store procedure to perform this but
when I do not fill the date textbox, SQL gives an error message about
filling the date textbox. In SQL I checked "accept null" for the date
column. What can I do?

Thanks.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TD | last post by:
This code doesn't work. Every posting I can find suggests that it should. If TypeOf controlname Is DTPicker then do something here End If I am using the Date Time Picker control and wish to...
3
by: Marauderz | last post by:
Hello guys, got a little question regarding the regional language settings . Anyway I got a Windows 2003 Server machine that was installed with the date format "dd/MM/yyyy" and location still...
3
by: RSB | last post by:
Hi Every one , IS there any Date Time Control with .Net. All i want to read is the Date and Time in a Single Field like 12/31/2004 09:23:23AM. if there is any then any examples for it. and if not...
0
by: BrianDH | last post by:
Hi I hate to ask this 'cause I know there must be a simple answer but I can't find it. Vb.net Windows form
0
by: BrianDH | last post by:
Hi I am using the DT control (Time Only Format) and I am looking for a way to get the focus to always be set to the hour. As it is now focus always goes back to the last place the cursor had been...
4
by: S Shulman | last post by:
Hi Users of the new system complain that it is not easy to use the new 'date control' because they can't select all the date parts and overkey the value. Is there a way of allowing the user to...
2
by: Darhl Thomason | last post by:
I'm converting my Access 2003 VBA app. I have a number of date fields in my db that I want to use the date/time picker control with, but if there is no entry in my database, I want the date/time...
0
by: venky | last post by:
Can anybody let me know is windows date time control with time format at hh:mm:ss , when i click to increment , by default it increments the hour value, but for some controls i want to increment...
4
by: Michel Posseth [MCP] | last post by:
I have a problem with the date time picker validate event wich i believe is a bug How to reproduce : throw on a form a date time picker control and a textbox control select the validating...
1
by: Susan Bricker | last post by:
Greetings. I have a report (actually all of my reports in an MDB) that I want to date/time stamp at the bottom. Previously, I had used the builtin function of Now(). I thought that would give...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.