我现在要做个delphi期末设计~
请问怎么在select语句的某字段传到字符串中。
例如~
我设置的字符串为xx
表student中有studentno和studentname
我现在要select studentno from student where studentno='某个学号';
然后我希望可以直接把studentno的值直接传到xx中。希望可以有人给我一个简单的方法~谢谢

解决方案 »

  1.   

    select studentno from student where studentno='某个学号'
    有点矛盾
      

  2.   

    语文问题,没看明白你要求什么。
    是要查询还是要修改?
    要修改就用update
      

  3.   


    var
      Str:String;
    begin
      With Qry do
      begin
        Close;
        Sql.Clear;
        Sql.Text:='select studentname from student where studentno=:studentno';
        Parameter.ParameterByName('studentno'').Value:='';//用参数来避免注入
        Open;
        Str:=FieldByName('studentname').Asstring;
      end;
    end;
      

  4.   

    给你个建议,写个函数,用函数的返回值
    比如:function GetNameById(Aid: Integer): String;
    var
      Str:String;
    begin
      With Form1.Query1 do
      begin
        Close;
        Sql.Clear;
        Sql.Text:='select studentname from student where studentno=:studentno';
        Parameters.ParamByName('studentno').Value:=Aid;//用参数来避免注入
        Open;
        Str:=FieldByName('studentname').Asstring;
      end;
      Result := Str;
    end;
    然后,就可以再其他地方直接用了,比如:StudentName := GetNameById('06012345');
      

  5.   

    现在是不知道楼主倒底是要把xx 传到select语句中还是要把select后打开的表的stutentno列的值传入到xx中
    //如果是用tadoquery的话
    1、adoquery1.sql.text := 'select studentno from student where studentno = ''' + xx + '''';
    2、表查询到后直接 xx := adoquery1.fieldbyname('studentno').asstring; 
      

  6.   

    select studentno from student where studentno='某个学号';
    然后直接把studentno的值直接传到xx中或者是不要打开表,直接把select语句中的 '某个学号' 送入 xx中,那你这个 '某个学号' 是怎么来的呢?键盘输的?那你就再输一遍给xx, 从其它变量或窗口组件如tedit来的?那就直接把这个值给xx
      

  7.   

    另外我想知道这条语句的作用~
    Parameter.ParameterByName('studentno'').Value:=''如果没有以上这条语句的话会发生什么?有人可以举下例子吗?
      

  8.   

    这个是为sql里的参数(“:xxx”)提供实际内容