Field Cannot Be Null or Empty

  • dempsc 3 years ago

    I Created a C1TrueDBGrid whose datasource is a C1Dataset (frtDataSet) and whose datamember is a composite table (OrdersSum) in that dataset. The grid displays data from the 2 tables in the composite table (frtOrders and SUMMST). The user must enter 2 fields associated with frtOrders in the grid. The 2 fields together form the key to SUMMST. To make sure the user has entered valid data and satisfy the foreign key constraint, I created a BeforeColUpdate event that checks the simple table SUMMST in the frtDataSet after the user enters the 2nd field (frtoSfx). The first field is a character field. The 2nd field is a double.

    Private Sub tdbgTest_BeforeColUpdate(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs) Handles tdbgTest.BeforeColUpdate
    Dim strFltr As String = String.Format(SELECT_ORDER, tdbgTest.Columns(“frtoInv”).Value, tdbgTest.Columns(“frtoSfx”).Value)
    Dim fltrs As New C1.Data.FilterConditions
    Select Case e.Column.Name
    Case “frtoSfx”
    fltrs.Add(New C1.Data.FilterCondition(Nothing, “SUMMST”, strFltr))
    frtDataSet.Fill(fltrs, New String() {“SUMMST”})
    If frtDataSet.TableViews(“SUMMST”).Rows.Count <= 0 Then
    e.Cancel = True
    End If
    End Select
    End Sub

    When I run the program, I enter data in the first field and then the 2nd. It executes the code in the BeforeColUpdate event as expected and verifies that the order exists in SUMMST. However after it exits the event, is displays the following error:

    Field 'frtoSfx’ Can Not Be Null Or Empty

    That certainly isn’t the case since you can see from the code, I used the value in that column of the grid to do the lookup.

    When I remove the code that looks up the record in the SUMMST table, the error goes away.

    When I check the datatype of tdbgTest.Columns(“frtoSfx”).Value, it shows as a String. When I look at the grid designer, the column type shows as a Double (the datatype in the SUMMST table).

    What am I doing wrong??

  • 39p
    C1_AndreyD39p 3 years ago

    I’d rather use the AfterColUpdate event. The BeforeColUpdate is fired when a cell enters the edit mode. It’s too early.

    Regards,

    -Andrey

  • dempsc 3 years ago

    The problem with your suggestion is that the foreign key constraint error message displays (see my prior topic in this forum). That is, I don’t have a chance to get the SUMMST record into the dataset before the foreign key constraint is tested.

    The procedure I am using here is identical to the one I used in that prior topic where it works like a charm. The lookup proceeds without harming the column value used for update. However, this time there are 2 fields forming the key and one of them is a double.

    I checked and the BeforeColUpdate is fired after you type something in the column and then try to leave the column

  • dempsc 3 years ago

    Additional Info:

    If I bind the grid to the simple table frtOrders rather than the composite table, I get the same error if I do the lookup inside BeforeColUpdate

  • 39p
    C1_AndreyD39p 3 years ago

    > However after it exits the event, is displays the following error:
    >
    > Field 'frtoSfx’ Can Not Be Null Or Empty

    Could you please post the stack trace (see e.Exception.StackTrace in the C1TrueDBGrid.Error event handler)?

    > The problem with your suggestion is that the foreign key constraint error message displays

    When I tried it the error message displayed after processing the AfterColUpdate event (and after the AfterColEdit event). It would be interesting to see the stack trace for the foreign key constraint error as well.

    Thanks.

    -Andrey

  • dempsc 3 years ago

    I have attached the error message and stack trace for the Foreign key error I get when using the AfterColUpdate event like you suggested.

    I have also attached the error message and stack trace for the Field can not be Null error

    Attachments:
    1. null_stack_trace

      null_stack_trace.jpg

    2. frtoSfx_Error

      frtoSfx_Error.jpg

    3. foreign_key_stack_trace

      foreign_key_stack_trace.jpg

    4. Foreign_Key_error

      Foreign_Key_error.jpg

  • 39p
    C1_AndreyD39p 3 years ago

    I’m trying to reproduce the "Field Cannot Be Null or Empty" error. So I created a small sample (attached here). The configuration of the data schema is similar to your database. It works well on my machine however. I see no problem with dynamic loading the missed rows to the "Order Details" simple table when the user assigns values to the 2-column foreign key in the CompositeTable.

    Could you please take a look at this sample and modify it to make the problem visible?

    Thanks in advance.

    Regards,

    -Andrey

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.