UltraGrid bind Null or Empty cell error on save

Posts   
 
    
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 13-Oct-2005 12:01:05   

Hi

I am having a issue where I get the data from SQL server database table using LLBLGen and then bind it to Infragistic grid (winforms) using below code.

UltraGrid1.DataSource = oEntityCollection
UltraGrid1.DataBind()

This will show me all the rows from table (my table has around 1000 rows).

Now in CustomerName column in the grid shows CustomerName in each row and I want to make one of the CustomerName column's cell value to NULL or blank string, If i remove the data in the cell to make it BLANK or NULL then I click the SAVE button and i get below error.

I am using below code to save the data back to database.

If oEntityCollection.SaveMulti(True) > 0 Then
 Messagebox.Show "data saved"
End If

I am not sure why I am getting this error. It is working fine with DataGrid that comes with VS.NET 2003.

Please help me to solve this issue.


---------------------------
ERROR
---------------------------
Unable to update the data value: Object type cannot be converted to target type.

System.ArgumentException: Object type cannot be converted to target type.

   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)

   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)

   at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters)

   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)

   at SD.LLBLGen.Pro.ORMSupportClasses.EntityPropertyDescriptor.SetValue(Object component, Object value)

   at Infragistics.Win.UltraWinGrid.UltraGridRow.SetCellValue(UltraGridColumn column, Object val, Boolean suppressErrorMessagePrompt)

   at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValue(Object value, Boolean suppressErrorMessagePrompt)

   at Infragistics.Win.UltraWinGrid.UltraGridCell.set_Value(Object value)

   at Infragistics.Win.UltraWinGrid.UltraGridCell.CommitEditValue(Boolean& stayInEdit, Boolean fireDataError, Boolean forceDontThrowException)

Infragistics.Win.UltraWinGrid.UltraGridCell
---------------------------
OK   
---------------------------

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 13-Oct-2005 16:17:12   

It appears to me that the Grid of the VS.Net update the string field with an empty string, while the Infragestic grid tries to set it with value null, which fails.

You can work around this by handling the grid event of CurrentCellChanged or any equivilant event, and check for a null value and reset it to the datatype default value.

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 14-Oct-2005 03:37:36   

Hi

Thanks for the information, here what I am doing is building a application so that user do NOT have to open the SQL Server Enterprise Manager to modify the data in a table and just run this application (.exe) and able to modify the data in selected table via this application, Now in this application user can able to modify multiple rows and columns to BLANK / NULL and infragistic grid (winforms) is bind to the LLBLGen entity collection.

And user can set few cell/column in the grid to BLANK / NULL and I am getting the error I mentioned in first post.

I am desparately looking for a resoltion for this as I am doing the LLBLGen and Infragistic demo to the client to convience then to use both tools in the development team to make development faster and more productive.

Hope this helps.

Is there anyway I can post the screenshot here? and how?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 14-Oct-2005 09:50:12   

a screenshot can be posted as: [ img]your image url[/img]

To handle null values in a grid, you could opt for: - have a 'magic' value for 'null', like a blank string. You add event handlers to the grid's events that when the user fills in an empty string, you set the field's value to null (using SetNewFieldValue())

Every entity field's property checks if the value is null. If that's the case, you get the default value for the type, for string that's the empty string.

Frans Bouma | Lead developer LLBLGen Pro
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 14-Oct-2005 15:55:12   

Hi Otis

I have setup a event BeforeCellUpdate as following.


    Private Sub UltraGrid1_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles UltraGrid1.BeforeCellUpdate

        If TypeOf (e.NewValue) Is System.DBNull Then
            Dim entity As IEntity = CType(oEntityCollection, IList).Item(e.Cell.Row.Index)
            entity.SetNewFieldValue(e.Cell.Column.Key, Nothing)
        End If

Still I am having this issue, as Infragistic grid bound to LLBLGen Collection and internally IBindingList sets DBNull which raise an exception.

After I have put a "e.Cancel = True" line it now works. As it does not raise binding list event.

Thank you for your information, it works....

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 14-Oct-2005 19:21:33   

Hey, Frans. I wonder if a good feature would be to be able to desginate that a certain magic value means null? Something like:



Dim myEntity as Entity

myEntity.DefineNullValueForProperty(EntityFieldIndex.MyStringProperty, "")

myEntity.MyStringProperty = ""


Jeff...

<Edit>Removed VB/C# schizoprenia (removed a semi-colon)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 14-Oct-2005 20:17:15   

It's tempting, though magic values have one big downside: over time, with the system in production for some time, it can be a 'magic' value suddenly is required for the data input (9/9/99 comes to mind) and it was not foreseen. It's unlikely the developers back then are still working on that same system, and this can have serious consequences.

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 14-Oct-2005 20:29:34   

Otis wrote:

It's tempting, though magic values have one big downside: over time, with the system in production for some time, it can be a 'magic' value suddenly is required for the data input (9/9/99 comes to mind) and it was not foreseen. It's unlikely the developers back then are still working on that same system, and this can have serious consequences.

However, without nullable types one always works with magic values in order to flag that a given field should be null. Implementing the functionality in the DAL just makes it easier to maintain the system as one always knows where to look for it, instead of it being scattered across UI code all over the place. Perhaps the default magic value could be set in the Designer...

Jeff...

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 18-Oct-2005 06:29:30   

Thanks for your help, it worked perfectly!