请教怎样可以把MSSQL里的一个结果赋给MessageBox或 s: string???
例子如下:
1------------------------
procedure TForm16.Button1Click(Sender: TObject);
var s: string;
 begin  //
 s := '是否添加?';
application.MessageBox(PChar(s),'提示',MB_YESNO+MB_ICONQUEStION)=ID_YES )
end;//
2--------------------------
select max(a) from b
3--------------------------
怎么把 max(a) 这个值赋给s  ???  

解决方案 »

  1.   

    ADOQuery.SQL.Text := 'select max(a) as num from b ';
    ADOQuery.Open;
    s := ADOQuery.FieldByName().Asstring;
      

  2.   

    ADOQuery.SQL.Text := 'select max(a) as num from b ';
    ADOQuery.Open;
    s := ADOQuery.FieldByName('num').Asstring;
      

  3.   

    VAR S:STRING;with ADOQuery do
    begin
      close;
      sql.clear;
      sql.add('select max(a) from b');
      open;
      s := Fields[0].Asstring;
      showmessage(s)end;
      

  4.   

    ADOQuery.SQL.Text := 'select max(a) as num from b ';
    ADOQuery.Open;
    s := ADOQuery.FieldByName().Asstring;楼上都正确
      

  5.   

    string:=ADOQuery.FieldByName('字段1').Asstring;
      

  6.   


    ADOQuery1.close;
    ADOQuery1.SQL.Text := 'select max(a) as num from b ';
    ADOQuery1.Open;
    if ADOQuery1.RecordCount>0 then
      s := ADOQuery.FieldByName('num').Asstring;
      

  7.   

    select max(a) as num from b 肯定有返回一条记录,所以不用判断RecordCount是否大于0