是这样的,我的程序打开的时候,DBGrid里的第一条记录的计算字段数据无法显示,双击DBGrid的滚动条后数据就能正常显示了。数据源用的是Sqlserver2000里的Northwind
我用了两个ADOQuery,第一个用来查询products表里的所有记录,加了个计算字段CategoryName用来显示Categories表里CategoryName;
第二个ADOQuery的SQL语句为select CategoryName from Categories where CategoryID=:CategoryID
计算字段的代码:
procedure TForm1.ADOQuery1CalcFields(DataSet: TDataSet);
begin
try
ADOQuery2.Parameters.ParamByName('CategoryID').Value :=
DataSet.FieldByName('CategoryId').Value;
ADOQuery2.Active := true;
DataSet.FieldByName('CategoryName').Value :=
ADOQuery2.FieldByName('CategoryName').Value
finally
ADOQuery2.Active := false;
end;
end;百思不得其解,还请各位指教!!
我用了两个ADOQuery,第一个用来查询products表里的所有记录,加了个计算字段CategoryName用来显示Categories表里CategoryName;
第二个ADOQuery的SQL语句为select CategoryName from Categories where CategoryID=:CategoryID
计算字段的代码:
procedure TForm1.ADOQuery1CalcFields(DataSet: TDataSet);
begin
try
ADOQuery2.Parameters.ParamByName('CategoryID').Value :=
DataSet.FieldByName('CategoryId').Value;
ADOQuery2.Active := true;
DataSet.FieldByName('CategoryName').Value :=
ADOQuery2.FieldByName('CategoryName').Value
finally
ADOQuery2.Active := false;
end;
end;百思不得其解,还请各位指教!!
解决方案 »
- delphi下如何将十六进制的ASC2码转为十六进制
- 现在每天都要写垃圾代码 晕哦
- 谁有多媒体控件
- 如何清除Image构件上次用Canvas绘制的图形?
- str:= StrPas(msg.CopyDataStruct.lpData); ''''着段怎么写成vb的或者什么意思
- delphi还能支持多久?
- Delphi是否对DLL调用支持不好!
- 好烦,一个老问题
- 怎样能弹出一个确认对话框-DELPHI新手的问题
- 大虾们 在delphi7使用easygrid 中遇到一个问题,请教下easygrid使用怎么刷新?换下日期,表头的第一行怎么不会重新合并?谢谢!
- Delphi7的TcpServer和TcpClient的非阻塞方式如何用?
- 动态添加Frame请教,有代码。
我拷了另外程序里的一个ADODataSet,原来的CategoryName的FieldType用的是Lookup,改为Calculated搞定。
不过还是不清楚为什么会这样,有没有人能解释一下吗?