Sub DataTable problem RRS feed

  • Question

  • A main DataTable is related to a sub DataTable. When a new DataRow is added to the main DataTable, the DataRow PK value sometimes is not inserted into the foreign key field of a new added row in the sub DataTable. Why.
    Monday, November 1, 2010 3:26 PM

All replies

  • Hello,

    Would you please describe how did insert values into your sub DataTable? Is there any code snippet for that?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, November 3, 2010 4:45 AM
  • Hi Roahn,

    everything is created by using the Designer (DataSource, DataSet, TableAdapter, DataGridView, BindingNavigator, etc). I click the AddNew button of the BindingNavigator of the main table STOCKS. A TextBox is data bound to the PK field of the main table. Here I insert a valid value. Then I turn to a sub table e.g. MATSUPPLIER: I click the AddNew button of the BindingNavigator of that sub table. Here a new line also appears in the DataGridView for MATSUPPLIERS, but the main tables PK value I inserted there is not automatically added to the FK field of the sub table.

    So when saving, you have the error here:

      Public Function SaveData() As String
        Catch ex As Exception
          Return FormMgmt2.SaveDataExceptionHandle(Me, ex)
        End Try
        Return ""
      End Function

    Sometimes it works properly but most times it doesn't!?!


    Monday, November 8, 2010 7:16 AM