数据库中有一个表tabledm记录数据库各表的信息;表名(tablename),表说明(tablesm);通过combobox下拉菜单,选择不同的表,在dbgird中显示对应表的数据。
combobox的下拉列表是表说明;
procedure TForm1.ComboBox2Change(Sender: TObject);
begin
adotable1.close;
ADOQuery1.close;
ADOQuery1.SQL.clear;
ADOQuery1.sql.add('select tablename from tabledm where tablesm=combobox2.text');
ADOQuery1.open;
ADOTable1.TableName:=ADOQuery1.adoquery1.fieldbyname('TABLENAME').asstring;
Try
ADOTable.open;
except
showmessage('表不存在!'); 
end;end.
其中:adotable1.connection:=dataconnection1;
adodatasource1.connection:=dataconnection1;
adodatasource1.dataset:=adotable1;编译时,选择表的时候出现问题project1.exe raised exception class EoleException with message“ora-00904:无效列名“是怎么回事?

解决方案 »

  1.   

    'select tablename from '+combobox2.text
      

  2.   

    combobox2下拉菜单里放的是表的说明,不是表名啊,我改了上面的sql语句,还是会出现同样的问题,郁闷了
      

  3.   

    已经解决了,是sql语句写错了
    ADOQuery1.sql.add('select tablename from tabledm where tablesm=‘+quotedstr(combobox2.text));
      

  4.   

    檢查:ADOQuery1.sql.add('select tablename from tabledm where tablesm=combobox2.text');
    ADOQuery1.sql.add('select tablename from tabledm where tablesm=‘+quotedstr(combobox2.text));