- 2
- 0
- 约2.83千字
- 约 6页
- 2018-06-30 发布于天津
- 举报
【实例手把手】Delphi连接SQLServer2000.doc
【实例手把手】Delphi连接SQL Server 2000
分类: 数据库概论 2009-11-12 14:22 18387人阅读 评论(11) 收藏 举报 一、在Delphi7中连接MS SQL Server 2000的方法。
刚开始时界面如下:添加4个控件。
?
?
?设置控件属性过程:?
1、ADOConnection1设置
1)双击ADOConnection1,进行设置连接字符串(作用是:选取连接驱动方式和连接的数据库设置)。过程如下图所示:?
?
?2、ADOQuery1设置:?
1)ADOQuery1.connection属性为ADOConnection1;
2)ADOQuery1.SQL属性为select student.sno,sname,cname,grade from student,sc,course where student.sno=sc.sno and course.cno=sc.cno
3)ADOQuery1.Active设置为TRUE。?
3、DataSource1设置
DataSet属性为ADOQuery1?
4、DBGrid1设置DataSource属性设置为DataSource1.?
效果图:
?
二、通过Delphi7进行设计SQL查询的界面和程序实现。
?1、界面设计
添加Edit,Button和Label控件,如图摆放和设置基本属性。
?
?
2、在BitBtn1的Click事件内完成程序。(Edit1和Edit2的综合查询,共4种情况)
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
SqlStr:String;
begin
i:=0;
if edit1.Text then
i:=i+1;
if edit2.Text then
i:=i+2;
case i of
0:
begin
SqlStr:=select student.sno,sname,cname,grade from student,sc,course
+where student.sno=sc.sno and course.cno=sc.cno ;
adoquery1.Close; //关闭ADOQuery1,以便于进行SQL语句更新
adoquery1.SQL.Clear; //清空SQL语句
adoquery1.SQL.Add(sqlStr); //添加新的SQL
adoquery1.Open; //新SQL有效
end;
1:
begin
SqlStr:=select student.sno,sname,cname,grade from student,sc,course
+where student.sno=sc.sno and course.cno=sc.cno and sname=+edit1.Text+;
adoquery1.Close; //关闭ADOQuery1,以便于进行SQL语句更新
adoquery1.SQL.Clear; //清空SQL语句
adoquery1.SQL.Add(sqlStr); //添加新的SQL
adoquery1.Open; //新SQL有效
end;
2:
begin
SqlStr:=select student.sno,sname,cname,grade from student,sc,course
+where student.sno=sc.sno and course.cno=sc.cno and cname=+edit2.Text+;
adoquery1.Close; //关闭ADOQuery1,以便于进行SQL语句更新
adoquery1.SQL.Clear; //清空SQL语句
adoquery1.SQL.Add(sqlStr); //添加新的SQL
adoquery1.Open; //新SQL有效
end;
3:
begin
SqlStr:=select student.sno,snam
您可能关注的文档
最近下载
- 新职业英语职业综合英语2(第三版)VR版Unit+1+PPT课件.pptx VIP
- 2026年部编版新教材语文小学二年级下册全册教案(含教学计划).pdf
- 计算机应用基础教程(Windows10+Office2016)PPT全套完整教学课件.pptx VIP
- 烹饪原理课件.pptx VIP
- 眩晕晕厥意识障碍(共48张PPT).pptx VIP
- 军工科研院所基于组织变革的科技创新体系构建与实施.pptx VIP
- 在学习贯彻党的二十届四中全会精神研讨会上的讲话.doc VIP
- 电缆价格详细计算表.xls VIP
- 生产制造过程管理汇报.pptx VIP
- 部编编人教版四年级下册小学道德与法治全册精品课件PPT.pptx
原创力文档

文档评论(0)