现在的位置: 首页 > 综合 > 正文

简单数据库操作问题

2012年09月15日 ⁄ 综合 ⁄ 共 1610字 ⁄ 字号 评论关闭
简单数据库操作问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061219132437221.html
请问操作ACCESS数据库时  
  如果数据库是  
  表   word  
  字段   name   字段   pass  
   
  读access把所有的name   加入combobox控件中   然后   点里面的内容就在edit1.text中显示对应的pass内容

1。  
  with   QDate   do  
      begin  
          open;  
          First;  
          Repeat  
              combobox.Items.Add(FieldByName('name').AsString);  
              Next;  
          until   EOF;  
          Close;  
      end;  
  end;  
   
  2。在combobox的OnChange  
  with   QDate   do  
      begin  
          close;  
              QDate.sql.clear;  
              QDate.sql='slect   *   from   word   where   [name]   ='+combobox.Text;  
          open;  
              edit1.text:=FieldByName('pass').AsString;  
          Close;  
      end;  
  end;  
 

呵呵,错了句  
  QDate.sql.add('slect   *   from   word   where   [name]   ='+combobox.Text);

路过.同学....

分点分给我吧

要用哪个控件呢..?

天啊,我用ADOQuery1,

能告诉我第2个人说的用的是什么控件写的么?

或者谁能告诉我个新的方法么..!   感谢

搞定了   可是方法不行啊  
  1。  
  with   QDate   do  
      begin  
          open;  
          First;  
          Repeat  
              combobox.Items.Add(FieldByName('name').AsString);  
              Next;  
          until   EOF;  
          Close;  
      end;  
  end;  
   
  这里就没指定是word表的啊?...

我晕   对   ADOQuery     初始化的时候在   SQL语句中不是写的很清楚了   from   word   吗   ?    
  然后才对ADOQuery进行操作啊。   如果   用   ADOTable则就在   Name中指定不就好了

3个问题。  
  1、name最好不要作为字段名,这是数据库的保留字,如果要使用请这样写[name]  
  2、遍历数据集记录,使用while比较正规,这样写:  
  with   AdoDataSet   do  
  begin  
        if   active   then   active:=false;  
        commandtext:='select   *   from   word';  
        active:=true;  
        combobox1.clear;   combobox2.clear;  
        while   (not   eof)   do  
        begin  
              combobox1.items.add(FieldByName('Name').asstring);  
              combobox2.items.add(FieldByName('pass').asstring);  
              Next;  
        end;  
        Close;  
  end;  
  3、实现你的功能,请在combobox1的onchange时间里写:  
        Edit1.text:=combobox2.items[combobox1.itemindex];

字段名,好像不能使用参数吧?

抱歉!评论已关闭.