2
I have the following problem, when trying to register a new record in the database it presents me the following error
below follows the codes:
open the form for registration.
procedure TFMHome.lbl_IncOSClick(Sender: TObject);
begin
UDM.ADODSOs.Open;
UDM.ADODSPecas_ordem_servico.Open;
UDM.ADODSOs.Insert;
UDM.ADODSOsData_Abertura.AsDateTime:= Date;
UDM.ADODSOs.Post;
UDM.ADODSOs.Edit;
FMOs.showmodal;
end;
Registration inclusion:
procedure TFMOs.Image1Click(Sender: TObject);
begin
UDM.ADODSOs.Post;
Application.MessageBox(
'O registro foi incluido com sucesso.',
'Informação',MB_OK+MB_ICONINFORMATION);
//end;
end;
Database:
create table pecas (
ID_Peca int PRIMARY KEY IDENTITY (1,1) NOT NULL,
Nome varchar (50)NOT NULL,
Categoria varchar (20),
Unidade char (8),
Quantidade int NOT NULL,
Valor_Custo float NOT NULL,
Valor_Venda float NOT NULL,
Observacao varchar (max),
ID_Fornecedor INT NOT NULL FOREIGN KEY REFERENCES fornecedor (ID_Fornecedor)
)
create table veiculo (
ID_Veiculo int PRIMARY KEY IDENTITY (1,1) NOT NULL,
Placa varchar (15),
Modelo varchar (20),
Ano char (4),
Combustivel varchar (12),
Cor varchar (20),
N_Chassi varchar (30)NOT NULL,
Observacao varchar (max),
ID_CLIENTE INT NOT NULL FOREIGN KEY REFERENCES cliente (ID_CLIENTE)
)
create table ordem_servico(
ID_OrdemServico int PRIMARY KEY IDENTITY(1,1) NOT NULL,
Situacao varchar (20),
Km varchar (20),
Localizacao varchar (30),
Data_Abertura datetime,
Data_Fechamento datetime,
ID_Funcionario INT FOREIGN KEY REFERENCES funcionario (ID_Funcionario),
ID_Cliente INT FOREIGN KEY REFERENCES cliente (ID_Cliente),
ID_Peca INT FOREIGN KEY REFERENCES pecas (ID_Peca),
ID_Veiculo INT FOREIGN KEY REFERENCES veiculo (ID_Veiculo)
)
create table pecas_ordem_servico(
ID_PECAS_ORDEMSERVICO int PRIMARY KEY IDENTITY (1,1) NOT NULL,
ID_PECA INT NOT NULL FOREIGN KEY REFERENCES PECAS (ID_peca),
ID_OrdemServico int NOT NULL FOREIGN KEY REFERENCES ordem_servico (ID_OrdemServico),
Valor_Unit float NOT NULL,
Qtde int NOT NULL,
Total float NOT NULL,
)
but this is the order.Register Supplier > Register Part > Register Customer > Register Vehicle > Castrate Service Order containing Part, Customer, Vehicle
– Guilherme Lima
So either you register a part in a q order does not exist or at the time you register the Service Order containing Customer Order and Vehicle she is trying to place the relationship order request before the order. This kernel you have to check, the error message is clear, foreign key error, it has no different.
– Ricardo
What recommends to be done?
– Guilherme Lima
Put in the question there all the Inserts he’s doing, then I can show you the order to be executed. Persistence layers usually have a log function, which one are you using? You know how to use its log?
– Ricardo