This is a migrated thread and some comments may be shown as answers.

Batch Updates and Null Values

3 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
HarryS
Top achievements
Rank 1
HarryS asked on 21 Feb 2009, 12:58 PM
Hi,

I am using the Batch Update method as found in the help files as follows:

Hashtable newValues = new Hashtable(); 
                //The GridTableView will fill the values from all editable columns in the hash 
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); 
 
                //sqlUpdatePayments.UpdateCommand = String.Format("Update Customers SET ContactName='{0}' WHERE CustomerID='{1}'", newValues["ContactName"], editedItem.GetDataKeyValue("CustomerID").ToString()); 
                sqlUpdatePayments.UpdateCommand = String.Format("UPDATE [MainBookings] SET [PaidType] = '{0}' WHERE [ClassBookedID] = '{1}'", newValues["PaidType"].ToString(), editedItem.GetDataKeyValue("ClassBookedID").ToString()); 
                sqlUpdatePayments.Update(); 

When performing the update, the update fails when it encounters a Null value. (Not all the records always need a value)
The data in question is coming from the below BoundColumn,

<telerik:GridBoundColumn UniqueName="PaidType" DataType="System.String" ConvertEmptyStringToNull="true" HeaderText="PaidType" DataField="PaidType" />

Could someone advise how I can deal with these null values?

Thanks in advance.
Harry

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Feb 2009, 12:27 PM
Hi HarryS,

Please make sure that the 'PaidType' DataField in your DataBase allow null value.

Shinu
0
Accepted
Daniel
Telerik team
answered on 23 Feb 2009, 12:33 PM
Hello Harry,

Test the following modification:
sqlUpdatePayments.UpdateCommand =  
    String.Format("UPDATE [MainBookings] SET [PaidType] = '{0}' WHERE [ClassBookedID] = '{1}'",  
    (string)newValues["PaidType"],  
    editedItem.GetDataKeyValue("ClassBookedID").ToString());  

Note that ToString will cause an exception if the value is null..

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
HarryS
Top achievements
Rank 1
answered on 23 Feb 2009, 12:52 PM
Hi,

Daniel - That worked a treat; All works ok now.
So simple when you know how!!!

Shinu - I did check, and the fields were set to - 'Allow Nulls - Yes'.

Many Thanks,
Harry


Tags
Grid
Asked by
HarryS
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
HarryS
Top achievements
Rank 1
Share this question
or