“字段“COUNT(id)”没有数据集” Delphi 中的 TSQLQuery
抱歉我的英语不好,但我希望你能理解我:P
我正在尝试在代码中创建新的 TSQLQuery 组件,而不是将其放在表单上。我写了该代码:
var
sql:tsqlquery;
pole:TFMTBCDField;
....
sql:=tsqlquery.Create(self);
sql.SQLConnection:=ddm.konekszyn;
sql.SQL.Text:='SELECT COUNT(idrap) FROM raporty WHERE idkier="'+lvkierowcy.Selected.Caption+'";';
pole:=TFMTBCDField.Create(self);
pole.Name:='sqlilerap';
pole.FieldName:='COUNT(idrap)';
pole.FieldKind:=fkData;
pole.DisplayLabel:='COUNT(idrap)';
sql.Fields.Add(pole);
sql.Open;
showmessage(sql.FieldByName('COUNT(idrap)').AsString);
sql.Free;
pole.Free;
但是当我尝试访问数据时出现异常:
First chance exception at $75999617. Exception class EDatabaseError with message 'Field 'COUNT(idrap)' has no dataset'. Process htstrm2.exe (2308)
我应该做什么?
Sorry for my english, but i hope you'll understand me :P
I'm trying to create new TSQLQuery component in code, without placing it on form. I wrote that code:
var
sql:tsqlquery;
pole:TFMTBCDField;
....
sql:=tsqlquery.Create(self);
sql.SQLConnection:=ddm.konekszyn;
sql.SQL.Text:='SELECT COUNT(idrap) FROM raporty WHERE idkier="'+lvkierowcy.Selected.Caption+'";';
pole:=TFMTBCDField.Create(self);
pole.Name:='sqlilerap';
pole.FieldName:='COUNT(idrap)';
pole.FieldKind:=fkData;
pole.DisplayLabel:='COUNT(idrap)';
sql.Fields.Add(pole);
sql.Open;
showmessage(sql.FieldByName('COUNT(idrap)').AsString);
sql.Free;
pole.Free;
but i'm getting exception when i try to access data:
First chance exception at $75999617. Exception class EDatabaseError with message 'Field 'COUNT(idrap)' has no dataset'. Process htstrm2.exe (2308)
What should I do ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
甚至不做一个领域。诸如此类的查询仅返回一个字段。所以只需从 fields 数组中引用:
Don't even make a field. Queries such as this return one and only one field. So just reference from the fields array:
您的数据库驱动程序报告聚合表达式的空字段名称。
您的字段的别名:
Your database driver reports the empty field name for the aggregate expression.
Alias your field:
您必须将数据集显式分配给该字段,请尝试添加此行
再见。
You must explicitly assign the dataset to the field, try adding this line
Bye.
为返回的列指定别名。然后您可以通过该别名访问它:
Alias the column being returned. You can then access it by that aliased name:
尝试将此行添加到您的查询中:
Try adding this line to your query: