DBGrid不显示查询结果的问题 ( 积分: 100 )

  • 主题发起人 主题发起人 kutiny
  • 开始时间 开始时间
K

kutiny

Unregistered / Unconfirmed
GUEST, unregistred user!
运行以后会显示出所有记录,但是点击'查询'按钮之后就不显示记录了(只有空值和1会显示所有记录)。<br>请哥哥姐姐,大叔大伯,阿姨婶婶,爷爷奶奶们帮忙看看~~~~~<br>我比较苯,回答请写详细点,谢谢!<br><br>控件属性:<br> Query1:&nbsp;Active&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatabaseName&nbsp;&nbsp;&nbsp;&nbsp;xitong<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;*&nbsp;from&nbsp;shuju<br> DataSource1:&nbsp;DataSet&nbsp;&nbsp;&nbsp;&nbsp;Query1<br> DBGrid1:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSource&nbsp;DataSource1<br> ComboBox1:&nbsp;&nbsp;&nbsp;Items&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID&nbsp;name&nbsp;sex&nbsp;chusrq&nbsp;等(虽然表里用的是英文,但是能不能像DBGrid一样改用中文呢?)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xitong&nbsp;shuju&nbsp;表里有&nbsp;ID&nbsp;name&nbsp;sex&nbsp;chusrq&nbsp;等字段<br><br>代码:<br>unit&nbsp;Unit2;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;ImgList,&nbsp;ComCtrls,&nbsp;ToolWin,&nbsp;StdCtrls,&nbsp;Grids,&nbsp;DBGrids,&nbsp;DB,<br>&nbsp;&nbsp;DBTables,&nbsp;Buttons,&nbsp;ADODB;<br><br>type<br>&nbsp;&nbsp;TForm2&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;ToolBar1:&nbsp;TToolBar;<br>&nbsp;&nbsp;&nbsp;&nbsp;ToolButton2:&nbsp;TToolButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;ToolButton1:&nbsp;TToolButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;ImageList1:&nbsp;TImageList;<br>&nbsp;&nbsp;&nbsp;&nbsp;Table1:&nbsp;TTable;<br>&nbsp;&nbsp;&nbsp;&nbsp;DataSource1:&nbsp;TDataSource;<br>&nbsp;&nbsp;&nbsp;&nbsp;DBGrid1:&nbsp;TDBGrid;<br>&nbsp;&nbsp;&nbsp;&nbsp;Query1:&nbsp;TQuery;<br>&nbsp;&nbsp;&nbsp;&nbsp;ComboBox1:&nbsp;TComboBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit1:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button1:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;ComboBox2:&nbsp;TComboBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button2:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormClose(Sender:&nbsp;TObject;&nbsp;var&nbsp;Action:&nbsp;TCloseAction);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button2Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;ToolButton1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br><br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;Form2:&nbsp;TForm2;<br><br>implementation<br><br>uses&nbsp;Unit1,&nbsp;Unit3;<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TForm2.FormClose(Sender:&nbsp;TObject;&nbsp;var&nbsp;Action:&nbsp;TCloseAction);<br>begin<br>&nbsp;&nbsp;Form1.close;<br>end;<br><br><br>procedure&nbsp;TForm2.Button1Click(Sender:&nbsp;TObject);//查询<br>begin<br>&nbsp;&nbsp;with&nbsp;Query1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Close;<br>&nbsp;&nbsp;&nbsp;&nbsp;SQL.Clear;<br>&nbsp;&nbsp;&nbsp;&nbsp;SQL.Add('select&nbsp;*&nbsp;from&nbsp;shuju&nbsp;where&nbsp;''ComboBox1.Text''&nbsp;like&nbsp;''%'+Trim(Edit1.Text)+'%''');&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;open;<br>&nbsp;&nbsp;end;<br>end;<br><br>procedure&nbsp;TForm2.ToolButton1Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;Form3.show;<br>end;<br><br>end.<br>不知道这样有没有写清楚
 
ComboBox1:&nbsp;&nbsp;&nbsp;Items&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID号&nbsp;姓名&nbsp;性别&nbsp;AAA&nbsp;等<br><br>procedure&nbsp;TForm2.Button1Click(Sender:&nbsp;TObject);//查询<br>var<br>&nbsp;&nbsp;Str:&nbsp;String;<br>begin<br>&nbsp;&nbsp;Case&nbsp;ComboBox1.ItemIndex&nbsp;Of&nbsp;//注意顺序!!!<br>&nbsp;&nbsp;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Str:='ID';<br>&nbsp;&nbsp;&nbsp;1:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Str:='name';<br>&nbsp;&nbsp;&nbsp;2:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Str:='sex';<br>&nbsp;&nbsp;&nbsp;3:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Str:='chusrq';<br>&nbsp;&nbsp;End;<br>&nbsp;&nbsp;with&nbsp;Query1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Close;<br>&nbsp;&nbsp;&nbsp;&nbsp;SQL.Clear;<br>&nbsp;&nbsp;&nbsp;&nbsp;SQL.Add('select&nbsp;*&nbsp;from&nbsp;shuju&nbsp;where&nbsp;'+Str+&nbsp;'&nbsp;like&nbsp;''%'+Trim(Edit1.Text)+'%''');&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;open;<br>&nbsp;&nbsp;end;<br>end;
 
SQL.Clear;<br>&nbsp;&nbsp;&nbsp;&nbsp;SQL.Add('select&nbsp;*&nbsp;from&nbsp;shuju&nbsp;where&nbsp;'+ComboBox1.Text+'&nbsp;like&nbsp;'+''''+'%'+Trim(Edit1.Text)+'%'+''''+')';&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;open;
 
SQL.Add('select&nbsp;*&nbsp;from&nbsp;shuju&nbsp;where&nbsp;'+ComboBox1.Text+&nbsp;'&nbsp;like&nbsp;''%'+Trim(Edit1.Text)+'%''')&nbsp;<br>运行通过了~!谢谢!!!第二个问题能不能顺便答下呢?<br>ComboBox1:&nbsp;&nbsp;&nbsp;Items&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID&nbsp;name&nbsp;sex&nbsp;chusrq&nbsp;等(虽然表里用的是英文,但是能不能像DBGrid一样改用中文呢?)<br>就是我建表用的是英文名的字段,我想在ComboBox中显示中文;还有能不能自动添加数据库当中的字段名,不要到items&nbsp;里手动加?
 
第二个问题&nbsp;已回答!<br>可以取&nbsp;但转换中文描述可能会有问题
 
[:)]谢谢!<br>既然会有问题那就凑合着用好了.......
 
后退
顶部