How to NULL a Datetime Value

Posts   
 
    
HaulMark
User
Posts: 24
Joined: 11-Aug-2004
# Posted on: 17-Mar-2005 18:07:16   

I receive the following error when trying to save an entity after the user clears out a date component.

" An exception was caught during the execution of an action query: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

This error occurs when saving an entity where I have tried to NULL a datetime value via entity.fetchusingpk("pk") entity.setnewfieldvalue("DATETIME_COLUMNNAME", Nothing) entity.save()

How do I NULL a datetime that already has a datetime value?

Skeeterbug
User
Posts: 165
Joined: 21-May-2004
# Posted on: 17-Mar-2005 18:29:21   

You can't set a datetime to null. In my app, I make any dates not used 1900/1/1, and check for that. Hopefully there is a better way!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 18:31:39   

HaulMark wrote:

I receive the following error when trying to save an entity after the user clears out a date component.

" An exception was caught during the execution of an action query: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

This error occurs when saving an entity where I have tried to NULL a datetime value via entity.fetchusingpk("pk") entity.setnewfieldvalue("DATETIME_COLUMNNAME", Nothing) entity.save()

How do I NULL a datetime that already has a datetime value?

There were some issues with SetNewFieldValue(). Do you use the latest runtime libraries? What does entity.setnewfieldvalue("DATETIME_COLUMNNAME", Nothing) return? It should return true.

Frans Bouma | Lead developer LLBLGen Pro
HaulMark
User
Posts: 24
Joined: 11-Aug-2004
# Posted on: 17-Mar-2005 19:25:35   

Yes, I do have the most recent runtime libraries.

entity.setnewfieldvalue("DATETIME_COLUMNNAME", Nothing) does return TRUE. Evaluating the currentvalue though as a string is 12:00:00 AM.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 20:16:15   

HaulMark wrote:

Yes, I do have the most recent runtime libraries.

entity.setnewfieldvalue("DATETIME_COLUMNNAME", Nothing) does return TRUE. Evaluating the currentvalue though as a string is 12:00:00 AM.

huh? that's impossible. If it returns true, it has set the value. Hmm... I'll have to create a test for this, though there is no special code for datetime fields...

By most recent runtime libraries, I mean, you do run the 03162005 build ? (RuntimeLibraryVersion.Build). You evaluate CurrentValue through: entity.Fields("DATETIME_COLUMNNAME").CurrentValue ? Sorry for the silly questions.

Frans Bouma | Lead developer LLBLGen Pro
HaulMark
User
Posts: 24
Joined: 11-Aug-2004
# Posted on: 17-Mar-2005 21:52:09   

By most recent runtime libraries, I mean, you do run the 03162005 build ? (RuntimeLibraryVersion.Build). You evaluate CurrentValue through: entity.Fields("DATETIME_COLUMNNAME").CurrentValue ? Sorry for the silly questions.

Downloaded this morning. And the when I evaluate I'm using the statement described above.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 22:19:43   

HaulMark wrote:

By most recent runtime libraries, I mean, you do run the 03162005 build ? (RuntimeLibraryVersion.Build). You evaluate CurrentValue through: entity.Fields("DATETIME_COLUMNNAME").CurrentValue ? Sorry for the silly questions.

Downloaded this morning. And the when I evaluate I'm using the statement described above.

Ok, thanks. I'll try to reproduce it here.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 23:17:57   

I can't reproduce it with this test:


[Test]
public void NullableDateTimeTest()
{
    CustomerEntity newCustomer = EntityCreator.CreateNewCustomer(1);
    newCustomer.TestRunId = _testRunID;
    AddressEntity newAddress = EntityCreator.CreateNewAddress(1);
    newAddress.TestRunId = _testRunID;
    newCustomer.VisitingAddress = newAddress;
    newCustomer.BillingAddress = newAddress;
    OrderEntity newOrder = new OrderEntity();
    newOrder.Customer = newCustomer;
    newOrder.OrderDate = DateTime.Now;
    newOrder.RequiredDate = DateTime.Now;
    newOrder.TestRunId = _testRunID;

    Assert.IsTrue(newOrder.Save(true));

    OrderEntity fetchedOrder = new OrderEntity(newOrder.OrderId);
    Assert.IsTrue(fetchedOrder.SetNewFieldValue("RequiredDate", null));
    Assert.IsTrue(fetchedOrder.Save());
    OrderEntity fetchedOrder2 = new OrderEntity(newOrder.OrderId);
    Assert.IsTrue(fetchedOrder2.TestOriginalFieldValueForNull(OrderFieldIndex.RequiredDate));
    Assert.IsNull(fetchedOrder2.Fields["RequiredDate"].DbValue);
    Assert.AreEqual(DateTime.MinValue, fetchedOrder2.Fields["RequiredDate"].CurrentValue);
}

Initially I set the field to a value (RequiredDate). Then I fetch the entity (like you do), set the field to null, then save it again. Works. I refetch it, to see if the field was set to null. Works... Could you please check if I perform the right test here?

Frans Bouma | Lead developer LLBLGen Pro
HaulMark
User
Posts: 24
Joined: 11-Aug-2004
# Posted on: 18-Mar-2005 17:45:38   

Otis,

I've found my problem. It was with a databound DevExpress component. As usual LLBLGEN is right on and it is the users problem! Thanks for your input and quick responses. The support you provide is the best I have seen in the industry. Thanks!

I sure hope .NET2.0 will handle NULL values better than 1.1 does now.

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 18-Mar-2005 18:05:02   

HaulMark wrote:

Otis,

I've found my problem. It was with a databound DevExpress component. As usual LLBLGEN is right on and it is the users problem! Thanks for your input and quick responses. The support you provide is the best I have seen in the industry. Thanks!

Glad you found the problem! simple_smile And thanks for the compliments! smile

I sure hope .NET2.0 will handle NULL values better than 1.1 does now. Chris

Nullable types will be a great gain, I'll use them in the next version of llblgen pro.

Frans Bouma | Lead developer LLBLGen Pro