<由于是新手,所以会有很多问题要请教的>关于数据库的问题!

foxcai 2004-04-12 09:05:34
我用paradox做了一个表,表的结构我已经建立。

我再delphi中添加了DataSource1,table1,query1。
table1连接到了a123.db,数据源连接到了table1,query1连接到了datasource1。

然后我用Query1.SQL.Add执行sql语句。
现在我想执行这样的一个语句。
select max(Index) from table1;
既:Query1.SQL.Add('select max(Index) from table1');
然后执行Query1.ExecSQL;

现在我想把用'select max(Index) from table1'语句查询到的数据附值给tempIndex。

我该用什么函数把这个查询结果附值给tempIndex呢?
请指教!


...全文
96 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
foxcai 2004-04-13
  • 打赏
  • 举报
回复
经过我的试验,在Query1.ExecSQL;
之后应该加上Query1.Open;
或是直接用Query1.Open;


谢谢楼上的各位了!
foxcai 2004-04-12
  • 打赏
  • 举报
回复
你看我这样写对吗?

Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select max(Index) As temp from shangwu');
Query1.ExecSQL;
tempIndex := strtoint(query1.fieldbyname('temp').asstring);
ShowMessage(IntToStr(tempIndex));
hongama 2004-04-12
  • 打赏
  • 举报
回复
'select max(index) AS temp from table1';
tempindex:=stringtoint(query1.fieldbyname('temp').asstring);
foxcai 2004-04-12
  • 打赏
  • 举报
回复
怎么没有人来帮我解决呢?
求求你们帮帮我啦!?
foxcai 2004-04-12
  • 打赏
  • 举报
回复
好的我试一试先!
highbury 2004-04-12
  • 打赏
  • 举报
回复
Query1.ExecSQL;---->改为 Query1.Open;

跑下程序看看结果对不对
lzy6204 2004-04-12
  • 打赏
  • 举报
回复
var
tempIndex: integer;
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select max(Index) As temp from shangwu');
Query1.ExecSQL;
tempIndex := query1.fieldbyname('temp').asInteger;
ShowMessage(IntToStr(tempIndex));
end;
foxcai 2004-04-12
  • 打赏
  • 举报
回复
怎么没有人再帮我看看呢?

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧