|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 03, 2010 5:22 AM
Points: 11,
Visits: 9
|
|
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.
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Monday, May 27, 2013 8:10 AM
Points: 688,
Visits: 312
|
|
| Try To Insert Without Convert.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 03, 2010 5:22 AM
Points: 11,
Visits: 9
|
|
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)
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Monday, May 27, 2013 8:10 AM
Points: 688,
Visits: 312
|
|
try like this System.Data.SqlTypes.SqlDateTime sqlDateTime = new System.Data.SqlTypes.SqlDateTime(System.DateTime.Now);
convert your date to sql date then insert.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, August 02, 2011 3:36 AM
Points: 579,
Visits: 1,803
|
|
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)
---------------------------------------------------------------------------------
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 03, 2010 5:22 AM
Points: 11,
Visits: 9
|
|
thanks for your replies but i have done it by using variable of type DateTime? which allows null value. thanks alot
|
|
|
|