W
wm1010
Unregistered / Unconfirmed
GUEST, unregistred user!
我有一數據庫(sql server)中的表格的inh, 其中該表格的主key包括有以下字段:
PARTNO, LOC, TXDATE, TXTYPE, TXREF, TXMODE, TXCTR. 且建立表格的Sql如下:
Create Table INH(
PARTNO VARCHAR(25) NOT NULL,
LOC VARCHAR(8) NOT NULL,
TXDATE DATETIME NOT NULL,
TXTYPE VARCHAR(2) NOT NULL,
TXREF VARCHAR(12) NOT NULL,
TXMODE VARCHAR(1) NOT NULL,
TXCTR Float NOT NULL,
TXQTY Float,
TXREM TEXT);
現有以下代碼:
procedure TForm1.Button1Click(Sender: TObject);
var
gPartNo, gLoc, gTxType, gTxRef, gTxMode:String;
gTxDate:TDateTime;
gTxCtrouble;
Query_Inh:TAdoQuery;
begin
if not AdoTable1.Active then
AdoTable1.Open;
try
AdoConnection1.BeginTrans;
With AdoTable1 do
begin
Append;
FieldByName('PARTNO').asstring:='TT-R-2';
FieldByName('LOC').asstring:='AD001';
FieldByName('TXDATE').asDateTime:=Date;
FieldByName('TXTYPE').asstring:='AJ';
FieldByName('TXREF').asstring:='AJ20021203';
FieldByName('TXMODE').asstring:='N';
FieldByName('TXCTR').asFloat:=1;
FieldByName('TXQTY').asFloat:=12;
FieldByName('TXREM').asstring:='REMARK-TT-R-2';
Post;
end;
with AdoTable1 do
begin
gPartNo:=FieldByName('PARTNO').asstring;
gLoc:= FieldByName('LOC').asstring;
gTxDate:=FieldByName('TXDATE').asDateTime;
gTxType:=FieldByName('TXTYPE').asstring;
gTxRef:=FieldByName('TXREF').asstring;
gTxMode:=FieldByName('TXMODE').asstring;
gTxCtr:=FieldbyName('TXCTR').asFloat;
end;
Query_Inh:=TAdoQuery.Create(nil);
With Query_Inh do
begin
Connection:=Adoconnection1;
close;
Sql.Clear;
Sql.Add('Select * From INH ');
Sql.Add('Where PARTNO=:sPartNo and LOC=:sLoc and TXDATE=:sTxDate and ');
Sql.Add('TXTYPE=:sTxType and TXREF=:sTxRef and TXMODE=:sTxMode and TXCTR=:sTxCtr');
Parameters.ParamByName('sPartNo').Value:=gPartNo;
Parameters.ParamByName('sLoc').Value:=gLoc;
Parameters.ParamByName('sTxDate').Value:=gTxDate;
Parameters.ParamByName('sTxType').Value:=gTxType;
Parameters.ParamByName('sTxRef').Value:=gTxRef;
Parameters.ParamByName('sTxMode').Value:=gTxMode;
Parameters.ParamByName('sTxCtr').Value:=gTxCtr;
Open;
end;
ShowMessage(IntToStr(Query_Inh.RecordCount));
if AdoConnection1.InTransaction then
begin
AdoConnection1.RollBackTrans;
Query_Inh.Close;
Query_Inh.Free;
ShowMessage('Ok!');
end;
Except
AdoConnection1.RollbackTrans;
Query_Inh.Close;
Query_Inh.Free;
ShowMessage('Failed!');
end;
end;
當我還未提交前,用TAdoQuery查詢剛新增的這條記錄, 為何不能搜索出來, 得知
Query_Inh.RecordCount = 0; 但用bde連接卻可以查詢出來, 敬請各位高手指點!
先給100分! 不夠再加!!!
PARTNO, LOC, TXDATE, TXTYPE, TXREF, TXMODE, TXCTR. 且建立表格的Sql如下:
Create Table INH(
PARTNO VARCHAR(25) NOT NULL,
LOC VARCHAR(8) NOT NULL,
TXDATE DATETIME NOT NULL,
TXTYPE VARCHAR(2) NOT NULL,
TXREF VARCHAR(12) NOT NULL,
TXMODE VARCHAR(1) NOT NULL,
TXCTR Float NOT NULL,
TXQTY Float,
TXREM TEXT);
現有以下代碼:
procedure TForm1.Button1Click(Sender: TObject);
var
gPartNo, gLoc, gTxType, gTxRef, gTxMode:String;
gTxDate:TDateTime;
gTxCtrouble;
Query_Inh:TAdoQuery;
begin
if not AdoTable1.Active then
AdoTable1.Open;
try
AdoConnection1.BeginTrans;
With AdoTable1 do
begin
Append;
FieldByName('PARTNO').asstring:='TT-R-2';
FieldByName('LOC').asstring:='AD001';
FieldByName('TXDATE').asDateTime:=Date;
FieldByName('TXTYPE').asstring:='AJ';
FieldByName('TXREF').asstring:='AJ20021203';
FieldByName('TXMODE').asstring:='N';
FieldByName('TXCTR').asFloat:=1;
FieldByName('TXQTY').asFloat:=12;
FieldByName('TXREM').asstring:='REMARK-TT-R-2';
Post;
end;
with AdoTable1 do
begin
gPartNo:=FieldByName('PARTNO').asstring;
gLoc:= FieldByName('LOC').asstring;
gTxDate:=FieldByName('TXDATE').asDateTime;
gTxType:=FieldByName('TXTYPE').asstring;
gTxRef:=FieldByName('TXREF').asstring;
gTxMode:=FieldByName('TXMODE').asstring;
gTxCtr:=FieldbyName('TXCTR').asFloat;
end;
Query_Inh:=TAdoQuery.Create(nil);
With Query_Inh do
begin
Connection:=Adoconnection1;
close;
Sql.Clear;
Sql.Add('Select * From INH ');
Sql.Add('Where PARTNO=:sPartNo and LOC=:sLoc and TXDATE=:sTxDate and ');
Sql.Add('TXTYPE=:sTxType and TXREF=:sTxRef and TXMODE=:sTxMode and TXCTR=:sTxCtr');
Parameters.ParamByName('sPartNo').Value:=gPartNo;
Parameters.ParamByName('sLoc').Value:=gLoc;
Parameters.ParamByName('sTxDate').Value:=gTxDate;
Parameters.ParamByName('sTxType').Value:=gTxType;
Parameters.ParamByName('sTxRef').Value:=gTxRef;
Parameters.ParamByName('sTxMode').Value:=gTxMode;
Parameters.ParamByName('sTxCtr').Value:=gTxCtr;
Open;
end;
ShowMessage(IntToStr(Query_Inh.RecordCount));
if AdoConnection1.InTransaction then
begin
AdoConnection1.RollBackTrans;
Query_Inh.Close;
Query_Inh.Free;
ShowMessage('Ok!');
end;
Except
AdoConnection1.RollbackTrans;
Query_Inh.Close;
Query_Inh.Free;
ShowMessage('Failed!');
end;
end;
當我還未提交前,用TAdoQuery查詢剛新增的這條記錄, 為何不能搜索出來, 得知
Query_Inh.RecordCount = 0; 但用bde連接卻可以查詢出來, 敬請各位高手指點!
先給100分! 不夠再加!!!