首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi+access数据库查询,该怎么处理

2012-03-17 
delphi+access数据库查询我能用这样的代码么?procedure TForm5.Button1Click(Sender: TObject)beginadota

delphi+access数据库查询
我能用这样的代码么?
procedure TForm5.Button1Click(Sender: TObject);
begin
 
adotable1.close;
if radiobutton1.checked then
adotable1.sql.clear;
adotable1.sql.add('select*from 表2 where bianhao=:bianhao');
adotable1.parameters.parambyname('bianhao').value:=trim(edit1.text);
if edit1.text=''then
begin
  application.messagebox('请输入商品编号','提示信息',64);
  edit1.setfocus;
  exit;
end;
adotable1.open;
end;
但运行的时候,错误指在adotable1.sql.clear;
希望大侠们帮帮忙。。小弟是初学者

[解决办法]
adotable1.sql.add('select*from 表2 where bianhao=:bianhao');->
adotable1.sql.add('select * from 表2 where bianhao=:bianhao');
select*from 连在一块了


如果错误仍在:改在Adoquery控件试试

[解决办法]
他没有把错误代码提示贴上来,怎么猜?可能是中文空格,可能是其他的,他的好像少了BEGIN END
[解决办法]
adotable1.sql.add('select*from 表2 where bianhao=:bianhao');->
adotable1.sql.Text :='select * from 表2 where bianhao=:bianhao';
[解决办法]
错误:
1.adotable是没有SQL属性的,只能设置Tablename直接关联表,要用SQL就改成adoquery吧
2.select*from 注意空格select * from
3.adotable1.close;最好放在if radiobutton1.checked then里面
4.if radiobutton1.checked then要加上begin...end 
5.if edit1.text='' then判断放在if radiobutton1.checked then这个判断外面

最终代码:

Delphi(Pascal) code
procedure TForm5.Button1Click(Sender: TObject);begin  if edit1.text=''then  begin    application.messagebox('请输入商品编号','提示信息',64);    edit1.setfocus;    exit;  end   else if radiobutton1.checked then  begin    with adoquery1 do    begin      close;      sql.clear;      sql.add('select * from 表2 where bianhao=:bianhao');      parameters.parambyname('bianhao').value:=trim(edit1.text);      open;    end;  end;end;
[解决办法]
换一个adoquery试试。
[解决办法]
TADOTable 是没有SQL属性的。如果要用这个属性可用TADOQuery.

热点排行