Hi,
I have a group box, that contains 5 text boxes and 5 masked textboxes. I wrote the code when user enters the data into all controls than user clicks button, the data saved into database table.
Here is my problem:
when the user doesnt want to enter data into some textboxes.I want to add it into the database with out any error.
Actually my present code giving me error if user leaves one text box also.
How can i do it?
Darma
Loading
VulpesPosted Jul 24, 2012, 7:35 AM
Notice that it's never necessary to explicitly test whether a bool expression is true.
Notice also that it's not necessary to convert dtParsedDate to a DateTime, as it's a DateTime already.
darma tejaPosted Jul 24, 2012, 7:28 AM
thanks allot for your fast replies.
If i don't convert null to datetime, it is giving me error.
because:
you can check this one: if i write like this it is giving me error of "can not implicit conversion between system.datetime and null"
(DateTime.TryParse(maskedTextBox1.Text, out dtparsedDate) == true ? Convert.ToDateTime(dtparsedDate) : null)
Darma
VulpesPosted Jul 24, 2012, 7:10 AM
If you use Convert.ToDateTime(null) when building your SQL command, then you'll end with a string containing this:
"01/01/0001 00:00:00"
which may be an invalid value for the corresponding column in the database.
Santhosh's point is that you should use "null" instead which should then be translated to NULL in the database assuming (Hemant's point) that the column allows nulls.
Santhosh Kumar JayaramanPosted Jul 24, 2012, 7:08 AM
darma tejaPosted Jul 24, 2012, 6:56 AM
If user does not enters the date, it is working well.
Only my problem with textboxes only.
Darma
Santhosh Kumar JayaramanPosted Jul 24, 2012, 6:47 AM
darma tejaPosted Jul 24, 2012, 6:46 AM
Here is my code:
Is user does not enter data in one textbox, than it is giving error.
Whatever user does not enter the data, that should save in the table1 as nulls.
Darma
Santhosh Kumar JayaramanPosted Jul 24, 2012, 6:35 AM
Hemant KumarPosted Jul 24, 2012, 6:28 AM