combobox 以完成对应 “姓名”字段
 
如何实现 当选择“张三”时 “年龄”字段显示在 Label 中 “性别”显示在 edit中
 
 
麻烦说的详细点 我用的是 adoquery
刚学 有很多地方不懂 谢谢给位帮忙

解决方案 »

  1.   

    with adoquery do
    begin
      active := false;
      SQL.TEXT := 'SELECT 年龄,性别 FROM 表 where name = '''+combobox1.text+''' '
      active := true;
      
      label.caption:= fieldbyname('年龄').asstring;
      edit1.text := fieldbyname('性别').asstring;
    end;
      

  2.   

    在 combobox1 的onchange事件里写入上述代码即可
      

  3.   

    1.重新根据姓名去查询
    2.把年龄,性别等,也添加到combobox中,用AddObject方法
      

  4.   

    相当于
    sql.add('SELECT 年龄,性别 FROM 表 where name = '''+combobox1.text+''' ')
      

  5.   

    ADOQuery.Close;
    ADOQuery.SQL.Text:='select 姓名,年龄,性别 from 表名 where 姓名="'+ComboBox.text+'"';
    ADOQuery.Open;
    Lable.Caption:=ADOQuery.FieldByName('年龄').AsString;
    Edit.Text:=ADOQuery.FieldByName('性别).AsString; 这样写的话没有问题  
    按上述的话 会报错 是不是我还有什么地方没有设置好 还是 
      

  6.   

    引号有问题。
    ADOQuery.SQL.Text:='select 姓名,年龄,性别 from 表名 where 姓名="'+ComboBox.text+'"';
    应该是 
    ADOQuery.SQL.Text:='select 姓名,年龄,性别 from 表名 where 姓名='''+ComboBox.text+'''';
      

  7.   

    不是设置好,是查询的连接字符串
    with ADOQuery do begin
      Acitve:=False;
      SQL.Text:='SELECT 姓名,年龄,性别 FROM 表名 WHERE 姓名='''+ComboBox.Text+'''';
      Active:=True;
      Label.Caption:=FieldByName('年龄').AsString;
      Edit1.Text:=FieldByName('性别').AsString;
    end;你在试试