Revert Date back to NULL

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
 
G

Guest

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
 
B

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

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.
 
A

Arnshea

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>).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top