数据库增加出错,大神求助
delphi吧
全部回复
仅看楼主
level 2
增加新的记录的时候提示违反外键,但是我在SQL里面增加是可以的
2014年11月03日 05点11分 1
level 2
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
type
TForm10 = class(TForm)
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit5: TEdit;
Edit16: TEdit;
Edit17: TEdit;
Edit18: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
ComboBox6: TComboBox;
ComboBox7: TComboBox;
ComboBox8: TComboBox;
ComboBox9: TComboBox;
ComboBox10: TComboBox;
Button2: TButton;
ComboBox11: TComboBox;
ComboBox12: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form10: TForm10;
implementation
uses Unit6, Unit12;
{$R *.dfm}
procedure TForm10.Button1Click(Sender: TObject);
begin
ADOQuery1.Connection:=Form12.ADOConnection1 ;
DataSource1.DataSet:=ADOQuery1;
DBGrid1.DataSource:=DataSource1;
with adoquery1 do
begin
close;
sql.Clear;
sql.Add(*insert into list*);
sql.Add(*values(:lno,:lname,:lquality,:lsource,:lstandard,:lvaluation,:lgno,:luno,:launo,:lsuno,:lstorage,:lcontrol,:lsale,:lmanage,:ldiscount,:lnprice,:lrprice,:lprice)*);
ADOQuery1.Parameters.ParamValues[*lno;lname;lquality;lsource;lstandard;lvaluation;lgno;luno;launo;lsuno;lstorage;lcontrol;lsale;lmanage;ldiscount;lnprice;lrprice;lprice*]:=varArrayof([edit1.Text,edit2.Text,ComboBox1.Items[ComboBox1.ItemIndex],ComboBox2.Items[ComboBox2.ItemIndex],edit5.Text,*01*,*00000001*,ComboBox5.Items[ComboBox5.ItemIndex],ComboBox6.Items[ComboBox6.ItemIndex],ComboBox7.Items[ComboBox7.ItemIndex],ComboBox11.Items[ComboBox11.ItemIndex],ComboBox12.Items[ComboBox12.ItemIndex],ComboBox8.Items[ComboBox8.ItemIndex],ComboBox9.Items[ComboBox9.ItemIndex],ComboBox10.Items[ComboBox10.ItemIndex],edit16.Text,edit17.Text,edit18.Text]);
execsql;
showmessage(*增加物料成功!*);
adoquery1.sql.text:=*select * from list*;
close;
adoquery1.Active:=true;
end;
end;
procedure TForm10.Button2Click(Sender: TObject);
begin
ADOQuery1.Connection:=Form12.ADOConnection1 ;
DataSource1.DataSet:=ADOQuery1;
DBGrid1.DataSource:=DataSource1;
with adoquery1 do
begin
adoquery1.close;
sql.Clear;
adoquery1.sql.text:=*select * from list*;
close;
execsql;
adoquery1.Active:=true;
end;
end;
end.
2014年11月03日 05点11分 2
level 2
不沉
2014年11月03日 06点11分 3
level 12
看下你自己的约束条件吧。很明显的提示你约束冲突了。
2014年11月03日 06点11分 4
但是我插入的数据在约束表中是存在的
2014年11月03日 11点11分
回复 看见与追寻 :存在了还怎么增加?什么叫约束?
2014年11月04日 00点11分
level 2
SOS
2014年11月03日 11点11分 5
1