请高手们帮帮忙拉,这个东东我不会,刚学DELPHI没几天(100分)

  • 主题发起人 主题发起人 lsjqn
  • 开始时间 开始时间
L

lsjqn

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一数据库如下<br>测点号 &nbsp; 检查次 &nbsp; 检查时间<br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;2003-10-01 &nbsp; <br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp;2004-10-01<br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;2005-10-01<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;2005-01-01<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp;2006-01-01<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;2006-01-10<br>然后用DBGRID按<br>按如下方式显示,如何写程序<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;检查次<br>测点 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5<br>1 &nbsp; &nbsp;2003-10-01 2004-10-01 &nbsp; 2005-10-01<br>2 &nbsp; &nbsp;2005-01-01 2006-01-01<br>3 &nbsp; &nbsp;2006-01-10<br><br>我用的是ADO+dbgrideh弄的,如果您能给个例子,我会更加的感谢。<br>十分感谢!
 
这个最好用stringgrid
 
请问,在这里有例子没有,那位大虾有例子给我发一个过来,liusjqn@126.com
 
没例子,你还是用stringgrid吧,取了数据集后,按条件往里写好了
 
用stringgrid可以,取了数据集后,符合条件的就往里写,stringgrid中每一格的定位是 StringGrid1.Cells[1,1]:='123';具体的就由你自己去发挥了。
 
stringgrid<br>简单实现
 
用SQL语句即可:<br>假设你的原表名为:abc<br>select a.测点号,b.sj as j1,c.sj as j2,.... from abc a<br>left join <br> &nbsp;(select 测点号,检查时间 as sj from abc where 检查次=1) b ON a.测点号=b.测点号<br>left join<br> &nbsp;(select 测点号,检查时间 as sj from abc where 检查次=2) c ON a.测点号=c.测点号<br>....<br>group by a.测点号
 
goodjsh你好,<br>你能不能具体的给我讲讲,我刚学,还不太明白<br>谢谢,最好给个例子,<br>liusjqn@126.com
 
unit hepl;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, DB, ADODB, StdCtrls, Grids;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;ADOConnection1: TADOConnection;<br> &nbsp; &nbsp;ADOQuery1: TADOQuery;<br> &nbsp; &nbsp;StringGrid1: TStringGrid;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>i:integer;<br>begin<br> &nbsp;ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/shiyan/Student.mdb;Persist Security Info=False';<br> &nbsp;ADOQuery1.Connection:=ADOConnection1;<br> &nbsp;ADOQuery1.Close;<br> &nbsp;ADOQuery1.SQL.Clear;<br> &nbsp;ADOQuery1.SQL.Add('select * from 101');<br> &nbsp;ADOQuery1.Open;<br> &nbsp;ADOQuery1.First;<br> &nbsp;for i:=0 to ADOQuery1.RecordCount-1 do<br> &nbsp;begin<br> &nbsp;//根据你的需要往里写就行了 ...<br> &nbsp; &nbsp;{********************}<br> &nbsp; &nbsp;StringGrid1.Cells[0,i]:=ADOQuery1.Fields[1].AsString;<br> &nbsp; &nbsp;{********************}<br> &nbsp; &nbsp;ADOQuery1.Next;<br> &nbsp;end;<br>end;<br><br>end.<br>===========================<br>试试这段程序,弄明白了。再根据你的需要往StringGrid1里写吧!
 
再补充一下:<br>ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/shiyan/Student.mdb;Persist Security Info=False';<br>是数据库D:/shiyan/Student.mdb及所在路径;<br>ADOQuery1.SQL.Add('select * from 101');<br>101是数据表,改成你的就可以了!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部