数据库 查询要点分析 ,vb6.0

显示结果的控件,

使用MSHFlexGrid控件

首先右击控件,属性中设置显示的列,行.

行数在程序执行过程中动态添加


一 ;在窗体的加载时候显示各列的标题

With myFlexGrid

.CellAlignment = 4

.TextMatrix(1, 0) = "学号"

.TextMatrix(1, 1) = "姓名"

.TextMatrix(1, 2) = "性别"

.TextMatrix(1, 3) = "出生日期"

.TextMatrix(1, 4) = "班号"

.TextMatrix(1, 5) = "联系电话"

.TextMatrix(1, 6) = "入校日期"

.TextMatrix(1, 7) = "家庭住址"

End With

cellalignment设置文本的显示方式,4,表示居中对齐

Textmartrix(1,0) 表示设置第一行,第一列单元格内容


以查询成绩为例:

首先定义三元素,

字符串 字符串 记录集

然后选择查询方式

根据所选的查询方式选择查询语言

如果按学号:

Sql= "select * from student_Info where student_

如果按姓名

Sql= "select * from student_Info where student_Name='trim(txtName.text)'

按班级

Sql= "select * from student_Info where class _No='trim(txtClassNo.text)'

这些还可以一起查询

之间用and 连

然后设置查询结果的排序方式

连接一个字符串 "order by student_ID"


接着使用函数

executeSQL 查询所要的结果

最后显示所要的结果

Do While Not mrc.EOF

.Rows = .Rows + 1

.CellAlignment = 4

.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)

.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)

.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)

.TextMatrix(.Rows - 1, 3) = Format(mrc.Fields(3), "yyyy-mm-dd")

.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)

.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)

.TextMatrix(.Rows - 1, 6) = Format(mrc.Fields(6), "yyyy-mm-dd")

.TextMatrix(.Rows - 1, 7) = mrc.Fields(7)

mrc.MoveNext

Loop

只要查询到的记录数不为空,则一直添加

行数加一

添加记录

添加完一次 ,向下移动一个记录