procedure TForm1.DBGrid1CellClick(Column: TColumn); with ADOQuery1 do begin sql.Clear; sql.Add('select * from authors where aul_name=:aul_name'); Parameters.ParamByName('aul_name').Value := Column.Field.AsString; //上面这里就是把你点击的方格的内容传到sql语句中 //并作为条件重新查找 open; edit1.Text := inttostr(RecordCount); //上面就是把重新查找的结果返回到edit中 end; end;
注: authors是表名 第一个aul_name是字段名 第二个aul_name是参数名
按楼上大哥的方法我试了下,单击时会出现错误提示框: --------------------------- Debugger Exception Notification --------------------------- Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72B9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue. --------------------------- OK Help --------------------------- procedure TForm1.DBGrid2CellClick(Column: TColumn); begin with adoquery1 do begin sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); parameters.ParamByName('单位编号').Value:=column.Field.AsString; open; edit42.Text:=inttostr(recordcount); end; end;
procedure TForm1.ADOQuery1AfterScroll(DataSet: TDataSet); begin Edit1.Text:=adoquery1['company']; end;
楼上兄弟的方法的确可行,只要单击dbgrid可是还是会出现错误提示。 --------------------------- Debugger Exception Notification --------------------------- Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72C9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue. --------------------------- OK Help ---------------------------
procedure TForm1.DBGrid2CellClick(Column: TColumn); begin with adoquery1 do begin sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); parameters.clear; parameters.addparameter; parameters[0].name:='单位编号'; parameters[0].datatype:=ftstring; parameters[0].direction:=pdinput; parameters.ParamByName('单位编号').Value:=column.Field.AsString; open; edit42.Text:=inttostr(recordcount); end; end;
procedure TForm1.DBGrid1CellClick(Column: TColumn); begin with test do begin Close; sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); ParamByName('单位编号').Value := Column.Field.AsString; Open; Edit1.Text:=Query1.FieldByName('ID').Asstring; end; end;
with test do 里的 test 应该改为Query1写错了,呵!测试过了,符合楼主的要求!
--------------------------- Debugger Exception Notification --------------------------- Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72C9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue. --------------------------- OK Help --------------------------- 楼上的兄弟,可是按你的代码,我还是没试起来,数据是出现了,但老出现这个错误提示。 procedure TForm1.DBGrid2CellClick(Column: TColumn); begin with adoquery1 do begin sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); parameters.ParamByName('单位编号').Value:=column.Field.AsString; open; edit42.Text:=fieldbyname('ID').AsString; end; end;
去看一下李维写的那本ADO的书,上面写了这个例子..这本书网上有下载的..
smiler007(笑一笑)叫什么名字啊`?
procedure TForm1.DBGrid2CellClick(Column: TColumn); var temp:string; begin temp:=clumn.Field.AsString; with adoquery1 do begin sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); parameters.ParamByName('单位编号').Value:=temp; open; end; edit42.Text:=adoquery1.fieldbyname('ID').AsString; end; //这样试试.....
procedure TForm1.DBGrid2CellClick(Column: TColumn); var temp:string; begin temp:=clumn.Field.AsString; with adoquery1 do begin close;//先关闭联接 sql.Clear; sql.Add('select ID from 交款明细 where 单位编号=:单位编号'); parameters.ParamByName('单位编号').Value:=temp; open; end; edit42.Text:=adoquery1.fieldbyname('ID').AsString; end; //这样试试.....
with ADOQuery1 do
begin
sql.Clear;
sql.Add('select * from authors where aul_name=:aul_name');
Parameters.ParamByName('aul_name').Value := Column.Field.AsString;
//上面这里就是把你点击的方格的内容传到sql语句中
//并作为条件重新查找
open;
edit1.Text := inttostr(RecordCount);
//上面就是把重新查找的结果返回到edit中
end;
end;
authors是表名
第一个aul_name是字段名
第二个aul_name是参数名
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72B9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
procedure TForm1.DBGrid2CellClick(Column: TColumn);
begin
with adoquery1 do
begin
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
parameters.ParamByName('单位编号').Value:=column.Field.AsString;
open;
edit42.Text:=inttostr(recordcount);
end;
end;
begin
Edit1.Text:=adoquery1['company'];
end;
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72C9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
begin
with adoquery1 do
begin
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
parameters.clear;
parameters.addparameter;
parameters[0].name:='单位编号';
parameters[0].datatype:=ftstring;
parameters[0].direction:=pdinput;
parameters.ParamByName('单位编号').Value:=column.Field.AsString;
open;
edit42.Text:=inttostr(recordcount);
end;
end;
begin
with test do
begin
Close;
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
ParamByName('单位编号').Value := Column.Field.AsString;
Open;
Edit1.Text:=Query1.FieldByName('ID').Asstring;
end;
end;
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004E72C9 in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
楼上的兄弟,可是按你的代码,我还是没试起来,数据是出现了,但老出现这个错误提示。
procedure TForm1.DBGrid2CellClick(Column: TColumn);
begin
with adoquery1 do
begin
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
parameters.ParamByName('单位编号').Value:=column.Field.AsString;
open;
edit42.Text:=fieldbyname('ID').AsString;
end;
end;
var
temp:string;
begin
temp:=clumn.Field.AsString;
with adoquery1 do
begin
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
parameters.ParamByName('单位编号').Value:=temp;
open;
end;
edit42.Text:=adoquery1.fieldbyname('ID').AsString;
end;
//这样试试.....
var
temp:string;
begin
temp:=clumn.Field.AsString;
with adoquery1 do
begin
close;//先关闭联接
sql.Clear;
sql.Add('select ID from 交款明细 where 单位编号=:单位编号');
parameters.ParamByName('单位编号').Value:=temp;
open;
end;
edit42.Text:=adoquery1.fieldbyname('ID').AsString;
end;
//这样试试.....