Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my form,

I have a maskedtextbox for my date value, If a user clicks CURRENT Button, my process will ignore value from maskedtextbox which is empty, But when user clicks PROCESS button, value from maskedtextbox is included in inserting new record unto my sql server.

My customize default for maskedtextbox is "00/00/0000"
in runtime, and CURRENT button is click, maskedtextbox value is " / / "
If the user clicks PROCESS, maskedtextbox value will be what the User enters.

I'm having error saving to sql server when maskedtextbox is empty or value is " / /".
Posted

Hello,

does your datetime column accepts null value. if yes then why dont you pass null value when user press CURRENT Button.

Thanks
sanjeev.
 
Share this answer
 
Comments
Alan Tuscano 4-Aug-11 3:58am    
Hi Sanjeev

Yup, it does, i've checked it also just to be sure and it allows null.

How will I pass a Null value..

maskedtextbox value is " / /"

SSQL = "INSERT INTO resibo ( recpno, recpdt, .............) values " & _
"(" & textbox1.text & ",'" & maskedtextbox & "'.........


Thanks for the quick reply sanjeev. Ü
[no name] 4-Aug-11 4:04am    
you must be checking which button is getting pressed. on current button press replace the maskedtextvalue with null.

just check with if condition if maskedtextbox.text= " / /" then maskedtext.text=null; check with this.
You will have an error inserting it anyway, if you are using an SQL Date field: the format for all such dates follows the ISO standard "yyyy-MM-dd".

1) Convert your MaskedTextBox to a DateTime. Report any errors, as they indicate bad dates which would cause an error on SQL Server anyway.
2) Hand the DateTime value to the database as a Parameter. If your database field accepts nulls, then you might want to pass that for empty fields instead.

You might want to consider using a DateTimePicker instead of a textbox, as teh user cannot enter a bad date with thet, and it already gives you a DateTime value automatically.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900