Relationship of two Tables with a DataSet containing two Tables

0

Good Afternoon Staff

I need help to make the relationship of two tables , so when I click on the DataGridView of DG_TitulosaReceber, the parcels for each title appear in the DG_NumerodeParcelas below.

I want to create the Synchronization of the two tables , to no load, show the record of the title to receive in the DataGridView from above , and show the respective plots (of this title) in the DataGridView below . Even using a next button and back , so switch to the next records by linking the Receivable Title and their installments.

In FormLoad it should be loaded by typing the Received Title (1st DataGridView) (1st table Titles to receive) with the Number of Parcels of that title (2nd DataGridView) (2nd table Number of Receivables).

Without the relationship, I can do Load, but without synchronism. It does not make a mistake, the relationship I tried to do is aborting when I open the form.

Follow the code below:

public partial class Entrada_Titulos_a_Receber : Form
{
    private DataSet TitulosareceberRelacionamento;


    private void Entrada_Titulos_a_Receber_Load(object sender, EventArgs e)
    {
         // Criando a Relação entre Tabelas Entrada_Titulos_a_Receber X Numero_Parcelas_a_Receber

         TitulosareceberRelacionamento = new DataSet();
         DataRelation data_relationReceber = new DataRelation(
              "EntradaTitulosReceberXNumeroParcelas",
              TitulosareceberRelacionamento
                          .Tables["Entrada_Titulos_a_Receber"]
                          .Columns["dataGridViewTextBoxColumn1"],  
              TitulosareceberRelacionamento
                          .Tables["Numero_Parcelas_a_Receber"]
                          .Columns["dataGridViewTextBoxColumn14"]);

         TitulosareceberRelacionamento.Relations.Add(data_relationReceber);

         this.numero_Parcelas_a_ReceberTableAdapter
                  .Fill(this.sGFRenaissanceDataSetEntradaTitulosReceberXnumeroParcelas
                                        .Numero_Parcelas_a_Receber);
         this.entrada_Titulos_a_ReceberTableAdapter
                  .Fill(this.sGFRenaissanceDataSetEntradaTitulosReceberXnumeroParcelas
                                        .Entrada_Titulos_a_Receber);

         // this.entrada_Titulos_a_ReceberBindingSource.DataSource = DataContextFactory.DataContext.Entrada_Titulos_a_Recebers;
         // this.numeroParcelasaReceberBindingSource.DataSource = DataContextFactory.DataContext.Numero_Parcelas_a_Recebers;


     }
}

Note: System aborts when trying to open the Form. Visual Studio Response, When Opening the Input_Titules_to_Receive Form:

NullReferenceException Was Unhandlded

  An unhandled exception of type 'System.NullReferenceException'   occurred in SGFRenaissance.exe Additional information:   object not set to an instance of an object.

     

Trobleshooting tips: Check to determine if the object is null before   calling the method. use the "new" keyword to create an object   instance. Get General help for this exception

     

View Detail ... (system message)

     

System.NullReferenceException {"Object reference not set to   an instance of an object. "}

I ask your help to create the relationship of tables because in the DataSource SGFDaRenaissanceDataSetEntranceTitlesReceiveXnumberParcels was created in the Wizard as "Relationship" No secondary key "ForeignKey" because using the Keys in the relationship gave error.

I created the above DataSet with the Wizard (creating the query with the two tables) and it worked by displaying the contents of the tables correctly. I checked the operation in SQL Server - all ok. The two Tables are together in the DataSet above, I dragged the first one into a DataGridView, and the second into the other DataGridView. They have the fields correctly in the DataGridView. When I open the form, (without the relationship code) the grids are filled out normally. But with the relationship of the tables gives error.

Tables Structure:

Entrada_Titulos_a_Receber - Titulo       
Cod_Entrada_Titulos_a_Receber -> Int ----> chavePrimaria - Identity yes
Cod_Cliente               -> Int
Numero_NF                 -> Varchar(20)
Data_NF                    -> Datetime
Valor_NF                   -> Decimal(18,2)
Cod_Receita                -> Int
Data_Vencimento             -> Datetime
Numero_Parcelas            -> Decimal(3,0)
Valor_Pago_a_Vista         -> Decimal(18,2)
Cod_Status_Titulo          -> Int
Historico                 -> Varchar(50)
Data_Login                -> Datetime
Login_Name                -> Varchar(15)
--------------------------------------------------
Numero_Parcelas_a_Receber
Cod_Entrada_Titulos_a_Receber -> Int ----> chavePrimaria Recebe o valor da 
                                                         Primeira tabela
Cod_Numero_Parcelas_Receber -> Int ----> chavePrimaria - Identity yes
Numero_Parcela         -> Decimal(3,0)
Data_Vencimento        -> Datetime
Valor_Parcela         -> Decimal(18,2)
Historico             -> Varchar(25)
Cod_Status_Titulo     -> Int

The tables are with 3 records in the first, and 6 in the second (number of parcels) Should a DataSet be created for each table? but what would the relationship be like?

Thank you very much for the help. Flávio Rocha.

    
asked by anonymous 20.11.2018 / 14:16

0 answers