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.
Setting the Nullable property on the column to insert empty strings when null does work but now I have empty strings in the database instead of nulls, is there anyway around this that is what I am trying to avoid.
If I catch the onUpdateRecord event and convert any empty strings I find into nulls I can solve that buit it would be nice to not have to go through the checking of every string column to convert it back to null
If setting Nullable to empty string works, then it sounds like my theory was correct and your data source cannot accept nulls. This has nothing to do with the grid, it's a issue with your data source.
What are you using as the data source of the grid? What data type is the field in question?
I am setting a bindingsource for the grid and the binding source has as its datasource a class which has a member inherited from a BindingList using something like
this.editingBindingSource.DataMember = "Records"; this.editingBindingSource.DataSource = typeof(PS.DAL.Schedules.ScheduleRecurringGetDal.QueryResults);
And the Records definition on that class are derived from BindgList
public class DalList<RecordType>: BindingList<RecordType>
Okay, but that doesn't answer my second question. What is the data type of the field you are using? My guess is that the type is DateTime, which means it cannot accept a null value because DateTime is a struct.
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.
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.