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

VulpesRank #55 · 29.2K reputationPosted Jul 24, 2012, 3:35 AM EDT
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.
Hemant KumarRank #1,202 · 1.5K reputationPosted Jul 24, 2012, 2:28 AM EDT
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 2:35 AM EDT
darma tejaRank #3,199 · 449 reputationPosted Jul 24, 2012, 2:46 AM EDT
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 JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 2:47 AM EDT
darma tejaRank #3,199 · 449 reputationPosted Jul 24, 2012, 2:56 AM EDT
If user does not enters the date, it is working well.
Only my problem with textboxes only.
Darma
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 3:08 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 24, 2012, 3:10 AM EDT
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.
darma tejaRank #3,199 · 449 reputationPosted Jul 24, 2012, 3:28 AM EDT
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