0
Good Afternoon everyone
I need help to do the relationship of two tables, to click on the Dg_title Datagridview, appear in the Dg_number below the installments of each title.
I want to create the Synchronism of the two tables, to no load, show the record of the title to be received in Datagridview from above, and show the respective shares (under this title) in the Datagridview from below. Even using a button, next and come back, so that it changes to the next records, linking the Title to receive and its installments.
In Formload must be loaded, linking the Title to receive (1º Datagridview)(1st table Titles to receive) with the Number of Installments of that title (2nd Datagridview)(2nd table Number of Installments to receive).
Without the relationship, I can do Load, but no timing. No mistake, with the relationship I tried to do is aborting when opening 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 Open Form Incoming:
Nullreferenceexception Was Unhandlded
An unhandled Exception of type 'System.Nullreferenceexception' occurred in Sgfrenaissance.exe Additional information: De reference object not defined for an object instance.
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 defined for an instance of an object."}
I ask for your help to Create the relationship of the Tables because in Datasource Sgfdarenaissancedatasetentradatitulosreceber xnumeros parcelas was created in Wizard as "Relationship" No secondary key "Foreignkey" because using the Keys in the relationship gave error.
I created the Dataset above, 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 on SQL Server - everything ok. The two Tables are together in the Dataset above, I dragged the first to a Datagridview, and the second to the other Datagridview. The fields are correctly in the Datagridview. When I open the form, (without the relationship code) the grids are filled in normally. But with the relationship of the tables gives error.
Structure of the Tables:
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 have 3 records in the first, and six in the second (number of plots) Should a Dataset be created for each table ? but how would the relationship be?
Thank you so much for your help. Flávio Rocha.
Debugging, where the error occurs?
– Leandro Angelo
really??
sGFRenaissanceDataSetEntradaTitulosReceberXnumeroParcelas
– Leandro Angelo
The error occurs when opening the form. When I call in the main menu, in the Load form, it stops. It is in the code I sent, the error messages when the system aborts.
– Flavio Rocha 2018
Where, on which line?
– Leandro Angelo
Leandro, no load do Formulário Entrada_titulos_a_receber.Cs linha 48
– Flavio Rocha 2018