Sunday, February 19, 2012

inserting NULL into Datetime and int

Hello,

I have an asp.net page with different textboxes that put text into an sql database.
When I try to leave the textboxes blank that correspond with datatypes of int and datetime
in sql server it gives an error : I need to fill in these textboxes.

How can I solve this problem so I can leave the boxes blanc? What is the best sollution for this? I know I can set the types to String but then the user could fill in what he wants :)
Could you give me some advice on this please? All ideas are welcome.
Thanks !if you strictly want to enforce the user to enter the proper data and not mess up the system, use customvalidators for the textboxes.

for date, you can prbly have three textboxes for month, yr and day and validate it to numeric and when you add the values to db, concatenate them with a "/" in between.

or if the user leaves it blank, check if the txtDate.text = "" then use system.dbnull to enter null into the db.

HTH.|||Hey thanks ndinakar :)

Ok I've looked in the .net classes for this dbnull. There's no good example of how to do that.
Do I use this dbnull on the page script or in the database (for example in a stored procedure?)
Could you give an example please?(I'm very noob)

Thanks again for replying !

No comments:

Post a Comment