边
边城过客
Unregistered / Unconfirmed
GUEST, unregistred user!
SQL2000+DELPHI,三层设计。
服务器 :adoconnection--adoquery--datasetp
客户端 :sockt--cliendataset
在用clientdataset1查询了数据后,再用clientdataset1进行insert就不行了,提示:
clientdataset1:Field 'nian' not found.
第一个项目在jbqkb表中能insert,但第二个项目在jbqkb表中不能insert。
源代码如下:
procedure Tfrmsjcl.Button3Click(Sender: TObject);
var A01,A02,A03,A04,A05,A06,A07,A08,A09,A10:integer;
begin
with clientDataSet1 do
begin //查询正式表中是否有本月数据
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select * from jbqkb where nian='''+ComboBox1.Text+''' and yue='''+ComboBox2.Text+'''';
ClientDataSet1.Open;
end;
if ClientDataSet1.RecordCount>0 then //查询到记录
begin
ShowMessage('数据库中已有本月数据,请先删除,然后再重新生成!');
Exit;
end
else
begin
with clientDataSet1 do
ClientDataset1.insert;
clientdataset1.fieldbyname('nian').asstring:=ComboBox1.Text;
clientdataset1.fieldbyname('yue').asstring:=ComboBox2.Text;
clientdataset1.fieldbyname('bh').asstring:='01';
clientdataset1.fieldbyname('xm').asstring:='第一个项目';
clientdataset1.fieldbyname('tj01').AsFloat:=0;
ClientDataSet1.ApplyUpdates(-1);
//取上期末总人数
if trim(ComboBox2.text)='1' then //如果是1月,就得取上年12月份的值
begin
a:=IntToStr(StrToInt(ComboBox1.Text)-1);
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select tj01 as A01 from jbqkb where nian='''+a+''' and yue=''12'' and xm=''第二个项目''';
ClientDataSet1.Open;
A01:=ClientDataSet1.Fields[0].Value;
end
else //否则就得取上月份的值
begin
b:=IntToStr(StrToInt(ComboBox2.Text)-1);
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select tj01 as A01 from jbqkb where nian='''+ComboBox1.Text+''' and yue='''+b+''' and xm=''第二个项目''';
ClientDataSet1.Open;
A01:=ClientDataSet1.Fields[0].Value;
end;
with clientDataSet1 do
ClientDataset1.insert;
clientdataset1.fieldbyname('nian').asstring:=ComboBox1.Text; //在这一步报错
clientdataset1.fieldbyname('yue').asstring:=ComboBox2.Text;
clientdataset1.fieldbyname('bh').asstring:='02';
clientdataset1.fieldbyname('xm').asstring:='第二个项目';
clientdataset1.fieldbyname('tj01').AsFloat:=A01;
ClientDataSet1.ApplyUpdates(-1);
end;
服务器 :adoconnection--adoquery--datasetp
客户端 :sockt--cliendataset
在用clientdataset1查询了数据后,再用clientdataset1进行insert就不行了,提示:
clientdataset1:Field 'nian' not found.
第一个项目在jbqkb表中能insert,但第二个项目在jbqkb表中不能insert。
源代码如下:
procedure Tfrmsjcl.Button3Click(Sender: TObject);
var A01,A02,A03,A04,A05,A06,A07,A08,A09,A10:integer;
begin
with clientDataSet1 do
begin //查询正式表中是否有本月数据
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select * from jbqkb where nian='''+ComboBox1.Text+''' and yue='''+ComboBox2.Text+'''';
ClientDataSet1.Open;
end;
if ClientDataSet1.RecordCount>0 then //查询到记录
begin
ShowMessage('数据库中已有本月数据,请先删除,然后再重新生成!');
Exit;
end
else
begin
with clientDataSet1 do
ClientDataset1.insert;
clientdataset1.fieldbyname('nian').asstring:=ComboBox1.Text;
clientdataset1.fieldbyname('yue').asstring:=ComboBox2.Text;
clientdataset1.fieldbyname('bh').asstring:='01';
clientdataset1.fieldbyname('xm').asstring:='第一个项目';
clientdataset1.fieldbyname('tj01').AsFloat:=0;
ClientDataSet1.ApplyUpdates(-1);
//取上期末总人数
if trim(ComboBox2.text)='1' then //如果是1月,就得取上年12月份的值
begin
a:=IntToStr(StrToInt(ComboBox1.Text)-1);
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select tj01 as A01 from jbqkb where nian='''+a+''' and yue=''12'' and xm=''第二个项目''';
ClientDataSet1.Open;
A01:=ClientDataSet1.Fields[0].Value;
end
else //否则就得取上月份的值
begin
b:=IntToStr(StrToInt(ComboBox2.Text)-1);
ClientDataSet1.Close;
ClientDataSet1.CommandText:='select tj01 as A01 from jbqkb where nian='''+ComboBox1.Text+''' and yue='''+b+''' and xm=''第二个项目''';
ClientDataSet1.Open;
A01:=ClientDataSet1.Fields[0].Value;
end;
with clientDataSet1 do
ClientDataset1.insert;
clientdataset1.fieldbyname('nian').asstring:=ComboBox1.Text; //在这一步报错
clientdataset1.fieldbyname('yue').asstring:=ComboBox2.Text;
clientdataset1.fieldbyname('bh').asstring:='02';
clientdataset1.fieldbyname('xm').asstring:='第二个项目';
clientdataset1.fieldbyname('tj01').AsFloat:=A01;
ClientDataSet1.ApplyUpdates(-1);
end;