March 8, 2010 at 12:53 am
Hello,
I have a webform and if user doesn't select any date from the form then it will send null in the database,i am using typed datasets.
Is there a way to store null in smalldatetime format, because when i try to do it using my code it give me exception
if (d == "")
{
d = null;
}
int i = studentTable.InsertStudent(txtName.Text, Convert.ToDateTime(d));
exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
March 8, 2010 at 1:23 am
Try To Insert Without Convert.
March 8, 2010 at 2:56 am
studentTableAdapter studentTable = new studentTableAdapter();
string s = txtName.Text;
string d = txtDate.Text;
if (d == "")
{
d = null;
int i = studentTable.InsertStudent(txtName.Text, Convert.ToDateTime(d));
}
here's my code and i am using typed dataset in my application, without convertto.datetime it gives error that best overloaded function for insertstudent has some invalid argument(string,System.datetime)
March 8, 2010 at 3:24 am
try like this
System.Data.SqlTypes.SqlDateTime sqlDateTime = new System.Data.SqlTypes.SqlDateTime(System.DateTime.Now);
convert your date to sql date then insert.
March 8, 2010 at 3:37 am
I am not certain about ADO.NET but should not you set DBNULL.Value
to your variable d?
(Sorry if I am holding the other end of the stick)
---------------------------------------------------------------------------------
March 8, 2010 at 4:49 am
thanks for your replies
but i have done it by using variable of type DateTime? which allows null value.
thanks alot
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply