Error inserting data in SQLServer + Delphi

2

I have the following problem, when trying to register a new record in the database it presents me with the following error

Below is the code below:

open the form to register.

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;

Adding the registry:

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,
)
    
asked by anonymous 21.11.2015 / 11:56

1 answer

0

The problem is foreign key, it is trying to include a record that depends on a foreign key, but the table of that key does not have the registry.

The key name of your message might be to try to include a part in a service order that does not exist.

If you see that absolutely all keys are populated correctly in memory before embedding then checks if it is including in the right order, it may be that it is trying to include a part in the order before including the order.     

21.11.2015 / 19:14