各位大哥救命!关于数据库查询问题,5.1前得搞定呀。(100分)

  • 主题发起人 delphinewboy
  • 开始时间
D

delphinewboy

Unregistered / Unconfirmed
GUEST, unregistred user!
帮我看一下,系统数据库连接成功了,但是我在操作时他说我语法错误,
我就不知道错那了,请各位帮忙
提示的错误信{Project Projectaa.exe.raised exception class EoleException.with message.[Microsoft]
[ODBC DBase Driver] syntax error.in FROM.Clause process stopped.Use Step or Run to continue.}
我的程序如下:
procedure TForm1.BitBtn1Click(Sender: TObject);
var together,key:string;
begin
table:=combobox1.text;
together:='';
combobox2.text:=combobox2.Items[combobox2.itemindex];
key:=combobox2.Text;
if edit1.Text=''
then
begin
showmessage('请输入字段值以便查询');
edit1.setfocus;
end
else
begin
ADoQuery1.close;
AdoQuery1.SQL.Clear;
AdoQuery1.Sql.Add('select * from ' +Table+ ' where ' + key +' like "%'+edit1.Text+'%"');
AdoQuery1.open;
if AdoQuery1.RecordCount=0 then
MessageDlg('没有你要的记录',mtinformation,[mbok],0);
panel3.visible:=true;
Dbgrid1.visible:=true;
DBNavigator1.visible:=true;
panel4.visible:=false;
Dbgrid2.visible:=false;
DBNavigator2.visible:=false;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
var iCount,j:integer;
tables:Tstringlist;
begin
try
tables:=Tstringlist.create;
Adoconnection1.GetTableNames(tables,false);
for j:=0 to tables.count-1 do
combobox1.Items.add(tables.strings[j]);
finally
tables.free;
combobox1.itemindex:=0;
combobox1.Text:=combobox1.items[combobox1.itemindex];
table:=combobox1.text;
ADoQuery1.close;
ADoQuery1.sql.clear;
AdoQuery1.sql.add('select * from '+table);
AdoQuery1.open;
Groupbox1.caption:=table+'数据表内';
GroupBox2.caption:='根据企业名称查询'+table+'表:';
ADoDatasET1.Close;
AdoDataset1.CommandText:='';
ADoDataset1.commandText:='select * from '+Table;
AdoDataset1.open;
Combobox2.items.clear;
for icount:=0 to AdoDataSet1.Fields.count-1 do
begin
Combobox2.items.add(AdoDataset1.fields[icount].Fieldname);
end;
combobox2.itemindex:=0;
end;

end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var icount:integer;
begin
combobox1.text:=combobox1.Items[combobox1.itemindex];
table:=combobox1.Text;
ADoQuery1.close;
ADoQuery1.sql.clear;
AdoQuery1.sql.add('select * from '+table);
AdoQuery1.open;
Groupbox1.caption:=table+'数据表内';
GroupBox2.caption:='根据企业名称查询'+table+'表:';

ADoDatasET1.Close;
AdoDataset1.CommandText:='';
ADoDataset1.commandText:='select * from '+Table;
AdoDataset1.open;
Combobox2.items.clear;
for icount:=0 to AdoDataSet1.Fields.count-1 do
begin
Combobox2.items.add(AdoDataset1.fields[icount].Fieldname);
end;
combobox2.itemindex:=0;
panel3.visible:=true;
Dbgrid1.visible:=true;
DBNavigator1.visible:=true;
panel4.visible:=false;
Dbgrid2.visible:=false;
DBNavigator2.visible:=false;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var keyy,where:string;
begin
table:=combobox1.text;
if edit2.text='' then
begin
showmessage('请输入企业名称以便查询');
edit2.setfocus;
end
else
begin
keyy:=edit2.text;
if table='animals' then
begin
messagedlg('不能在animals数据表内查找相关的企业名称'+#13+'请另选别的数据表',mtinformation,[mbok],0);
PageControl1.ActivePageIndex:=0;
end
else begin
where:='select DISTINCT *,animals.name,animals.size from '+Table+',animals where animals.weight'+' like "%'+keyy+'%"';
where:=where+' and '+Table+'.企业名称 ="'+keyy+'"';
//where:='select * from 案卷,'+Table+' where 案卷.卷号'+'='+Table+'.'+keyy;
//where:='select * from '+Table+' where '+table+'.卷号'+' like "%'+keyy+'%"';
AdoQuery2.Close;
AdoQuery2.sql.Clear;
AdoQuery2.sql.add(where);
AdoQuery2.open;
if AdoQuery2.RecordCount=0 then
MessageDlg('没有你要的记录',mtinformation,[mbok],0);
panel4.visible:=true;
Dbgrid2.visible:=true;
DBNavigator2.visible:=true;
panel3.visible:=false;
Dbgrid1.visible:=false;
DBNavigator1.visible:=false;
end;
end;

end;

procedure TForm1.PageControl1Changing(Sender: TObject;
var AllowChange: Boolean);
var API:integer;
begin
API:=pageControl1.ActivePageIndex;
case API of
1:edit1.text:='';
2:edit2.text:='';
end;
end;

end.
还有就是我用adoquery连接我自己的数据库时连接成功,但是在执行时却连不上了,是怎么一回
事呀,我用的是delphi自带的paradox 别名dbdemo,各位一定要帮小弟一把呀。要是有愿意帮小
弟的请多多联系qq:12316730 在些小弟有礼了!
 
你是执行那步动作时出的错误?
 
语法错误在FROM子句。
select DISTINCT *,A.name,A.size from '+Table+' T,animals A where ......
将表名用个别名代替看看,还有Distinct能不能作用所有字段,也不太记得了,我很少用
这个Distinct来做唯一查询。
 
他说语法错误后就跳到projectaa中的Application.Run;句上了呀,可我感觉这没错呀,这是怎
么回事呀
 
你最好单步跟踪一下你的sql.text,看看是否是符合你的要求
 
FORM的程;序如下:
program Projectaa;

uses
Forms,
Unitaa in 'Unitaa.pas' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
 
procedure TForm1.FormCreate(Sender: TObject);
var iCount,j:integer;
tables:Tstringlist;
begin
try
tables:=Tstringlist.create;
Adoconnection1.GetTableNames(tables,false);
for j:=0 to tables.count-1 do
combobox1.Items.add(tables.strings[j]);
finally
tables.free;
combobox1.itemindex:=0;
combobox1.Text:=combobox1.items[combobox1.itemindex];
table:=combobox1.text;
ADoQuery1.close;
ADoQuery1.sql.clear;
AdoQuery1.sql.add('select * from '+table);
AdoQuery1.open;
Groupbox1.caption:=table+'数据表内';
GroupBox2.caption:='根据企业名称查询'+table+'表:';
ADoDatasET1.Close;
AdoDataset1.CommandText:='';
ADoDataset1.commandText:='select * from '+Table;
AdoDataset1.open;
Combobox2.items.clear;
for icount:=0 to AdoDataSet1.Fields.count-1 do
begin
Combobox2.items.add(AdoDataset1.fields[icount].Fieldname);
end;
combobox2.itemindex:=0;
end;
 
object Form1: TForm1
Left = 34
Top = 1
Width = 605
Height = 492
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 16
object Panel1: TPanel
Left = 0
Top = 0
Width = 579
Height = 449
TabOrder = 0
object Panel2: TPanel
Left = 0
Top = 0
Width = 577
Height = 233
TabOrder = 0
object PageControl1: TPageControl
Left = 1
Top = 1
Width = 575
Height = 231
ActivePage = TabSheet1
Align = alClient
TabOrder = 0
OnChanging = PageControl1Changing
object TabSheet1: TTabSheet
Caption = '选择数据表'
object Label1: TLabel
Left = 32
Top = 80
Width = 91
Height = 16
Caption = '请选择数据表:'
end
object ComboBox1: TComboBox
Left = 120
Top = 72
Width = 145
Height = 24
ItemHeight = 16
TabOrder = 0
Text = '房 屋'
OnChange = ComboBox1Change
end
end
object TabSheet2: TTabSheet
Caption = '查询字段'
ImageIndex = 1
object GroupBox1: TGroupBox
Left = 24
Top = 24
Width = 385
Height = 145
Caption = '房屋数据表内'
TabOrder = 0
object Label2: TLabel
Left = 24
Top = 32
Width = 91
Height = 16
Caption = '要查询的字段:'
end
object Label3: TLabel
Left = 24
Top = 88
Width = 52
Height = 16
Caption = '字段值:'
end
object ComboBox2: TComboBox
Left = 112
Top = 24
Width = 105
Height = 24
ItemHeight = 16
TabOrder = 0
Text = '编号'
end
object Edit1: TEdit
Left = 80
Top = 80
Width = 201
Height = 24
TabOrder = 1
end
end
object BitBtn1: TBitBtn
Left = 440
Top = 136
Width = 75
Height = 25
Caption = '开始查询'
TabOrder = 1
OnClick = BitBtn1Click
end
end
object TabSheet3: TTabSheet
Caption = '查询标题'
ImageIndex = 2
object GroupBox2: TGroupBox
Left = 40
Top = 24
Width = 417
Height = 129
Caption = '根据企业名称查询房屋表:'
TabOrder = 0
object Label4: TLabel
Left = 40
Top = 64
Width = 65
Height = 16
Caption = '企业名称:'
end
object Edit2: TEdit
Left = 112
Top = 56
Width = 241
Height = 24
TabOrder = 0
end
end
object BitBtn2: TBitBtn
Left = 472
Top = 128
Width = 75
Height = 25
Caption = '开始查询'
TabOrder = 1
OnClick = BitBtn2Click
end
end
end
end
object Panel3: TPanel
Left = 1
Top = 233
Width = 577
Height = 210
TabOrder = 1
object DBGrid1: TDBGrid
Left = 1
Top = 26
Width = 575
Height = 183
Align = alClient
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -13
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 1
Top = 1
Width = 575
Height = 25
DataSource = DataSource1
Align = alTop
TabOrder = 1
end
object Panel4: TPanel
Left = 0
Top = 0
Width = 577
Height = 209
TabOrder = 2
object DBNavigator2: TDBNavigator
Left = 1
Top = 1
Width = 575
Height = 24
DataSource = DataSource2
Align = alTop
TabOrder = 0
end
object DBGrid2: TDBGrid
Left = 1
Top = 25
Width = 575
Height = 183
Align = alClient
DataSource = DataSource2
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -13
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
end
end
end
object DataSource1: TDataSource
DataSet = ADOQuery1
Left = 129
Top = 321
end
object DataSource2: TDataSource
DataSet = ADOQuery2
Left = 217
Top = 329
end
object ADOConnection1: TADOConnection
ConnectionString =
'Provider=MSDASQL.1;Persist Security Info=False;User ID=paradox;D' +
'ata Source=dBASE Files;Initial Catalog=C:/Program Files/Common F' +
'iles/Borland Shared/aaa'
Provider = 'MSDASQL.1'
Left = 321
Top = 329
end
object ADOQuery1: TADOQuery
Connection = ADOConnection1
Parameters = <>
Left = 425
Top = 329
end
object ADOQuery2: TADOQuery
Connection = ADOConnection1
Parameters = <>
Left = 489
Top = 321
end
object ADODataSet1: TADODataSet
Connection = ADOConnection1
Parameters = <>
Left = 361
Top = 329
end
end
 
这里的人是不是瞧不起我们这些菜鸟呀,怎么不削这些问题呀,有点伤心呀,我的问题还是
没解决的呀,还忙哪位大哥能伸一只手来拉小弟一把呀,难倒真的要看我死在这儿吗?
 
你写了这么长的代码,你想累死偶门阿
 
我只是心急,主要是procedure TForm1.BitBtn2Click(Sender: TObject);和
procedure TForm1.BitBtn1Click(Sender: TObject);这两个里面的还望各位多多
帮忙了。小弟在此谢了。
 
是03年的五一吗?
 
to microming:
  虽然我很笨,但也许你也不比我聪明多少呀,你不会看看我贴子上的时间吗,虽然已经过
去了,但是,我的问题还没解决的呀,所以还往大家继续帮我呀,虽然我现在还在,但是这个
程序我到现在还没有做出来,所以也就延误了交工期了。但最终还得解决的呀。请大家多多帮
忙了。
 
顶部