加上一句
//注意这里是否报错!!不知道其他控件是否引用了datasource1
datasoure1.dataset:=nil;
close;
sql.clear;
sql.add('select * from table3');
open;
//注意这里是否报错!!不知道其他控件是否引用了datasource1
datasoure1.dataset:=nil;
close;
sql.clear;
sql.add('select * from table3');
open;
解决方案 »
- To:liangqingzhi 有个问题看你回答的很精彩,故特给你满分30分
- fastreport 2.51 在WIN98 下的打印问题
- 如何用鼠标实现image的移动?
- 简单问题,如何将提取的数据填入DBGRID,大家都来看看!
- 请问有没有控件能做出类似qq的用户那种动态按钮的
- dbgrid显示decimal数据类型的问题
- 请问怎样设计工作区的大小?(分不够再加,决不食言)
- 请问,在DELPHI中上传图片,不写到数据库中,只是写一个相对路径,不知怎么做?
- 急!!delphi 调用dll中函数问题
- query或table中用了lookup field后,就其慢无比.谁有办法解决?
- 各位大哥,如何判断一个edit输入的内容是否为合法的数字类型,有类似函数么?
- 不能用搜索引擎,只好麻烦大家,如何判断用Query 打开的一个数据集是空的呢??
或者我只操作table3时也不会!
我的table3 表中没有'myid'字段;
假若table3与table1 是一样的结构是不会出错的!
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from table1');
open;
datasoure1.dataset:=adoquery1;
//--------------------------------------------------------------------
adoquery2.close;
adoquery2.datasource:=datasource1;
adoquery2.sql.clear;
adoquery2.sql.add('insert into table2 values(:myID,:youHand,....)');
first;
while not eof do
begin
adoquery2.execsql;
//--------------------------------------------------------------
edit;
fieldbyname('UpLoad_Is').asboolean:=true;
post;
next;
end;
//--------------------------------------------------------------------
close;
sql.clear;
sql.add('select * from table3');
open;//到这里出错:adoquery1:field myID not find.
end;
table1与table2 是同样的结构。table3 没有字段'myID';
dbgrid1引用了数据源:datasoure1;
我想了几天也不知问题出在那里?
adoquery3.close;
adoquery3.sql.clear;
adoquery3.sql.add('select * from table3');
adoquery3.open;
我的dbgrid1 是 绑定了datasource1;
我该怎么样做呢???????我要显示datasource1中的内容呀!
to:jixinfa(DELHPI程序员)
程序设计时,adoquery1没有静态字段!
你说的很对,用adoquery3肯定不会出错!
但是我查询table3的目的也是为了
执行象table1、table2一样的操作!这是一个循环:
我的目的是将:table1 中的内容上载到table2;
table3..............table4;
table5..............table6;
........................................
我用adoquery1从table1,table3,table5.....选取记录;dbgrid1,dbgird2,
..................显示所选取的记录。
用adoquery2将数据从table1,table3,table5.....中写入table2,table4,
table6.......中!
所以我不可能使用其它adoquery1组件!
程序设计时,在DBGrid1的Columns属性中我没有做列定义。是动态的!
DataSource1关联到:adoquery2和dbgird1或dbgir2或dbgir3..........
但这些dbgrid组件全是没有作列定义的!
unit UpLoad;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, Buttons, ComCtrls, ExtCtrls;type
TFUpLoad = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
GroupBox1: TGroupBox;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
TabSheet6: TTabSheet;
TabSheet7: TTabSheet;
StatusBar1: TStatusBar;
DBGrid2: TDBGrid;
DBGrid3: TDBGrid;
DBGrid4: TDBGrid;
DBGrid5: TDBGrid;
DBGrid6: TDBGrid;
DBGrid7: TDBGrid;
DBGrid1: TDBGrid;
Label1: TLabel;
cmbMonth: TComboBox;
Label2: TLabel;
btnUpLoad: TBitBtn;
btnClose: TBitBtn;
CheckBox1: TCheckBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure btnUpLoadClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
{ Private declarations }
function upLoad(i:integer):boolean;
public
{ Public declarations }
end;var
FUpLoad: TFUpLoad;implementation
uses dldata;
{$R *.dfm}procedure TFUpLoad.FormClose(Sender: TObject; var Action: TCloseAction);
begin
dm.dlServer.Connected:=false;
dm.Q2.Close;
dm.Q2.Connection:=dm.dlconnection;
dm.Q2.DataSource:=nil;
action:=cafree;
end;procedure TFUpLoad.FormShow(Sender: TObject);
begin
cmbmonth.Items:=g_monlist;
cmbmonth.ItemIndex:=12;
try
dm.dlserver.Connected:=true;
statusbar1.Panels[1].Text:='已连接上远程服务器!';
btnUpLoad.Enabled:=true;
dm.Q2.Close;
dm.Q2.Connection:=dm.dlServer;
dm.Q2.DataSource:=dm.DQ1;
pagecontrol1.ActivePageIndex:=0;
PageControl1Change(self);
except
statusbar1.Panels[1].Text:='未建立与远程服务器的连接!';
btnUpLoad.Enabled:=false;
end;
end;procedure TFUpLoad.btnUpLoadClick(Sender: TObject);
var
i:integer;//----------------------------------procedure start-----------------------------------
begin
label2.Caption:='正在上载中....';
cmbmonth.Enabled:=false;
pagecontrol1.Enabled:=false;
btnupload.Enabled:=false;
btnclose.Enabled:=false;
checkbox1.Enabled:=false;
if not checkbox1.Checked then
begin
i:=pagecontrol1.ActivePageIndex;
if not upload(i) then
showmessage('上载失败!');
end//not checkbox1.checked
else begin
{ for i:=0 to pagecontrol1.PageCount-1 do
begin
pagecontrol1.ActivePageIndex:=i;
if not upload() then
begin
showmessage('上载失败!');
break;
end;//if not upload() then
end;//for i:=0 to pagecontrol1.PageCount-1 do }
end;//checkbox1.checked
cmbmonth.Enabled:=true;
pagecontrol1.Enabled:=true;
btnupload.Enabled:=true;
btnclose.Enabled:=true;
checkbox1.Enabled:=true;
label2.Caption:='上载完成!';
end;
procedure TFUpLoad.PageControl1Change(Sender: TObject);
begin
with dm.Q1 do
begin
case pagecontrol1.ActivePageIndex of
0:begin
close;
sql.Clear;
sql.Add('select * ');
sql.Add('from amm where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=dm.DQ1;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=nil;
end;//0
1:begin
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=dm.DQ1;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=nil;
close;
sql.Clear;
sql.Add('select * from dlamm where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
end;//1 dlamm
2:begin
close;
sql.Clear;
sql.Add('select * from fee where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=dm.DQ1;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=nil;
end;//2 fee
3:begin
close;
sql.Clear;
sql.Add('select * from dlfee where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=dm.DQ1;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=nil;
end;//3 fee
4:begin
close;
sql.Clear;
sql.Add('select * from Alarm where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=dm.DQ1;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=nil;
end;//4
5:begin
close;
sql.Clear;
sql.Add('select * from Account where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=dm.DQ1;
dbgrid7.DataSource:=nil;
end;//5
6:begin
close;
sql.Clear;
sql.Add('select * from Op_fee_record where (UpLoad_Is=0) and (Amonth='''+cmbmonth.text+''')');
open;
dbgrid1.DataSource:=nil;
dbgrid2.DataSource:=nil;
dbgrid3.DataSource:=nil;
dbgrid4.DataSource:=nil;
dbgrid5.DataSource:=nil;
dbgrid6.DataSource:=nil;
dbgrid7.DataSource:=dm.DQ1;
end;//6
end;//case
end;//dm.q1
end;procedure TFUpLoad.btnCloseClick(Sender: TObject);
begin
close;
end;
begin
dm.Q2.DataSource:=dm.DQ1;
dm.dlconnection.BeginTrans;
dm.dlServer.BeginTrans;
try
with dm do
begin
case i of
0:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into amm values(:ID,:Yh_ID,:Yh_Name,:Amonth,:Amm_Prior,:Amm_Cur,:ele,:Tran_Lose,:Cop_Lose,:Wire_Lose,:Sum_ele,:Price,:ele_Fee,:Benefit_Fee,:Latefee_Start,:Amm_Date,:Amm_Man,:Acroom_ID,:Lock,:Lock_Reason,:UpLoad_Is,:Re)');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Edit;
q1.FieldByName('UpLoad_Is').AsBoolean:=true;
q1.Post;
q1.Next;
end;//while not q1.eof
q1.Close;
q1.Open
end;//0
1:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into dlamm values(:Yh_ID,:Yh_Name,:Amonth,:AmmA_ID,:AmmB_ID,:AmmC_ID,:AmmA_Prior,:AmmB_Prior,:AmmC_Prior,:AmmA_Cur,:AmmB_Cur,:AmmC_Cur,');
q2.SQL.Add(':ele,:Tran_Lose,:Cop_Lose,:Wire_Lose,:Sum_ele,:Price,:ele_Fee,:Benefit_Fee,:Latefee_Start,:Amm_Date,:Amm_Man,:Acroom_ID,:Lock,:Lock_Reason,:UpLoad_Is,:Re)');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Edit;
q1.FieldByName('UpLoad_Is').AsBoolean:=true;
q1.Post;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//1
2:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into fee values(:Yh_ID,:Yh_Name,:Amonth,:Amm_Prior,:Amm_Cur,:ele,:Tran_Lose,:Cop_Lose,:Wire_Lose,:Sum_ele,:Price,:ele_Fee,:Benefit_Fee,');
q2.SQL.Add(':Price_Type,:ele_Price,:Add_Price,:Benefit_Type,:Benefit_Price,:Latefee_Start,:Latefee_End,:Latefee_Date,:Latefee,:amm_ID,:Capital,:Amm_Date,:Amm_Man,:Acroom_ID,:Lock,:Lock_Reason,:Re,:UpLoad_Is,:Latefee_Start');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//2
3:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into dlfee values(:Yh_ID,:Yh_Name,:Amonth,:AmmA_ID,');
q2.SQL.Add(':AmmB_ID,:AmmC_ID,:AmmA_Prior,:AmmB_Prior,:AmmC_Prior,:AmmA_Cur,');
q2.SQL.Add(':AmmB_Cur,:AmmC_Cur,:ele,:Tran_Lose,:Cop_Lose,:Wire_Lose,:Sum_ele,');
q2.SQL.Add(':Price_Type,:Price,:ele_Price,:Add_Price,:ele_Fee,:Benefit_Type,:Benefit_Price,:Benefit_Fee,:Latefee_Start,:Latefee_End,:Latefee_Date,:Latefee,:Sum_Fee,:Capital,:Pay_Date,:Pay_Acman,:Pay_Acroom,:Re,:UpLoad_Is');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//3
4:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add(':Alarm_Time,:Alarm_addr,:Op_Name,:Yh_ID,:Alarm_Events,:Alarm_reason,:Acroom_ID,:Amonth,:Alarm_Is,:UpLoad_Is');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//4
5:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into Account values(:Yh_ID,:Yh_Name,:Account_In,:Account_Time,:Account_Cur,:Amonth,:Op_Name,:acroom_ID,:Events,:UpLoad_Is,:Yh_Type,:Active');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//5
6:begin
q2.Close;
q2.SQL.Clear;
q2.SQL.Add('insert into Op_fee_Record values(:Op_Time,:Op_Addr,:Op_Name,:Op_Events,:Yh_ID,:Amonth,:acroom_ID,:Re,:UpLoad_Is');
q1.First;
while not q1.Eof do
begin
q2.ExecSQL;
q1.Next;
end;//while not q1.eof
q2.Close;
q2.SQL.Clear;
q1.Close;
q1.Open;
end;//6
end;//case
end;//with dm do
dm.dlServer.CommitTrans;
dm.dlconnection.CommitTrans;
dm.Q2.DataSource:=dm.DQ1;
result:=true;
except
dm.dlconnection.RollbackTrans;
dm.dlServer.RollbackTrans;
result:=false;
end;//try;
end;end.
你将Table1和Table2设置了主细关系,masterFields='MyID',以DataSource1关联,再看你的代码
close;
sql.clear;
sql.add('select * from table3');
open;//到这里出错:adoquery1:field myID not find.
DataSource1连到了Table3,此时实际上Table3和Table2建立了主细关系,而Table3中没有字段'MyID'.......
谢谢!我再想一想!你说的有道理!
小弟终于解决问题了,:):)
方法是:
在查询table3 表前加上一句:
adoquery2.datasource:=nil;
真是想不到,这么简单!!!!!!!!!!!
即:
把adoquery2 与 datasource1 的关联去掉!!!!!!!!!!