Set DateTime field to null

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 20-Dec-2005 20:27:28   

I have searched through all the threads on can find on setting a datetime field to null and have downloaded the latest release and I still cannot get this to work. I'm not getting any errors when doing this except that the field I'm trying to change doesn't get included in the update statement when the value of the field is null. When debugging the Shipment.SetNewFieldValue the base.SetNewFieldValue returns false which I think might have something to do with my problem, but I don't know how it works. In the end I would expect to only be seeing the ShippedDate field in the update statement as its the only field being changed, instead I'm getting every field except the one I changed.

Here is the code that I'm using.

DateTime selectedDate = this.picker.SelectedDate;
            if ( selectedDate == DateTime.MinValue )
                shipment.SetNewFieldValue((int)ShipmentFieldIndex.ShippedDate, null);
            else
                shipment.ShippedDate = selectedDate;

Here is the TSQL produced which does not include the field I'm updating.

exec sp_executesql N'UPDATE [WS2].[dbo].[Shipment] SET [CustomerOrderID]=@CustomerOrderID,
[CourierName]=@CourierName,[ShippingMethodName]=@ShippingMethodName,[TrackingNumber]=@TrackingNumber,
[InsuranceCost]=@InsuranceCost,[ShippingCost]=@ShippingCost,[ShippingCredit]=@ShippingCredit,
[CustomerNotes]=@CustomerNotes,[WSNotes]=@WSNotes,[FirstName]=@FirstName,[LastName]=@LastName,
[Address1]=@Address1,[Address2]=@Address2,[City]=@City,[State]=@State,[Province]=@Province,
[PostalCode]=@PostalCode,[Country]=@Country WHERE ( [WS2].[dbo].[Shipment].[ShipmentID] = @ShipmentID1)',
 N'@CustomerOrderID int,@CourierName varchar(30),@ShippingMethodName varchar(30),@TrackingNumber varchar(50),
@InsuranceCost smallmoney,@ShippingCost smallmoney,@ShippingCredit smallmoney,@CustomerNotes varchar(300),
@WSNotes varchar(300),@FirstName varchar(30),@LastName varchar(40),@Address1 varchar(50),@Address2 varchar(20),
@City varchar(40),@State varchar(100),@Province varchar(100),@PostalCode varchar(10),@Country varchar(60),
@ShipmentID1 int', @CustomerOrderID = 17, @CourierName = 'UPS', @ShippingMethodName = 'Ground',
@TrackingNumber = 'SLKDJGF89023', @InsuranceCost = $50.0000, @ShippingCost = $200.0000,
@ShippingCredit = $0.0000, @CustomerNotes = '', @WSNotes = '', @FirstName = '', @LastName = '',
@Address1 = '', @Address2 = '', @City = '', @State = '', @Province = '', @PostalCode = '', @Country = '',
@ShipmentID1 = 13
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 21-Dec-2005 02:40:38   

This may seem like a dumb question, but is the datetime field nullable? That should be returning true for you in order to set that field to null.