I have a grid that when populated may or may not have null values for a column that is a string.
If the data returned is already null everything works fine. If the string column had data and I step into the column and delete all the data I get a message stating that there is a Data Error - Unable to update the data value: Object of type 'System.DBNull' cannot be converted to type 'System.String'.
How can I allow a column to go back to a null value once it contained data?
It sounds to me like your data source doesn't accept DBNull, only an empty string. If that's the case, you can fix this by setting the Nullable property on the column.
I am not sure that may be it, but I am not certain where to verify this information. I can manually set the records on the data source to null without a problem. I am using a bindingsource and its datasource is a class inherited from a BindingList
I also tried checking the Nullable property on the column but it did not make any difference.
This is happening when I step out of the row that I deleted the string from and before the OnUpdateRecord event.
Okay, that makes sense, then. A String field can't accept DBNull. But it should be able to accept Null. Doesn't the Nulable property on the column have a choice for Null (not DBNull)?
It does have that as an option. Pretty sure I tried it but I will try it again and let you know thanks for the info.
I double checked and went I set it to NULL it still throws the db null error, only setting it to empty string seems to make a difference.
Well, something is clearly wrong there, then. Either the grid is not properly trying to save a Null (which seems unlikely, but is certainly possible) or something somewhere along the way is changing the null to a DBNull.
You should probably try to create a small sample projet that demonstrates this and Submit an incident to Infragistics Developer Support
What is the status of this? I am getting the same message except for a decimal field. This field will never be null, but when I delete all the characters from the field and try to leave the field I get that error message.
When you set the column.Nullable property, use the Nullable.Nothing enum value, it gives you null in C# and Nothing in VB.
The Nullable.Null gives you DBNull in the cell.
Default is Automatic, which gives you DBNull if allowed, and empty string else.
I had a similiar problem and found the solution on the EntitySpaces forum (as I'm using that as a DataSource):
http://community.entityspaces.net/forums/thread/5379.aspx
Essentially use:
foreach (UltraGridColumn column in this.grid.Rows.Band.Columns)
column.Nullable = Infragistics.Win.UltraWinGrid.Nullable.EmptyString;
}
Using CellDataError fixed my problem.
Thank-you
Hi,
Have you tried setting the Nullable property on the column?
What are you expecting the grid to do when the field is left blank, use a 0? You could handle the CellDataError event to suppress the error message and (I think) modify the value so it's valid.