Revert Date back to NULL

  • Thread starter Thread starter BD
  • Start date Start date
B

BD

I have sent several posts on this topic and feel my lack of
information is not helping to find the solution. I am developing
application in C# with Visual Studio 2005 to connect with remote SQL
Server 2005. On one form, I have a textbox bound to a datetime column
on the server. When the form loads a new record, this textbox is
blank. This is correct. However, once a valid date has been entered
into this textbox, it cannot be removed and NULL inserted back into
the column. I know it is possible, I am presently using MS Access
2003 to connect to this same server and table and if I delete the
date, NULL is inserted back into the table and my textbox shows blank
or empty string. If access can do this, I know C# can as well.

Thank you for all assistance.

BD
 
BD

Use Nullable DateTime (as long as you are in .Net 2.0 or better)

DateTime? foo = null;

if(foo.HasValue)
{
//Do work
}


Hope this helps.

David
 
BD

Use Nullable DateTime (as long as you are in .Net 2.0 or better)

DateTime? foo = null;

if(foo.HasValue)
{
//Do work

}

Hope this helps.

David

I am using .NET 2.0. I can successfully check if the textbox has an
empty string, however, I cannot get NULL inserted back to the database.
 
I have sent several posts on this topic and feel my lack of
information is not helping to find the solution. I am developing
application in C# with Visual Studio 2005 to connect with remote SQL
Server 2005. On one form, I have a textbox bound to a datetime column
on the server. When the form loads a new record, this textbox is
blank. This is correct. However, once a valid date has been entered
into this textbox, it cannot be removed and NULL inserted back into
the column. I know it is possible, I am presently using MS Access
2003 to connect to this same server and table and if I delete the
date, NULL is inserted back into the table and my textbox shows blank
or empty string. If access can do this, I know C# can as well.

Thank you for all assistance.

BD

Once you've detected that the textbox is empty find the currently
bound datarow then call DataRow.SetNull(<column bound to textbox>).
 
Back
Top