![]() |
#2
风吹过b2017-02-03 15:40
Private Sub ListKm()
Set Rst1 = New Recordset '使用的表对象 sql = "select * from 学科表 order by 序号" '定义SQL命令 Rst1.Open sql, db, 1, 3 '打开表,db 是数据连接 If Rst1.EOF Then '如果没有记录 GridDW.Clear '清除表格 GridDW.Rows = 1 '表格设置为一行 GridDW.FormatString = "^ 序号|^ 学科 |^ 总分 |^ 差生分 |^ 及格分 |^ 优秀分|^ 尖子分 " '表格头 Exit Sub Else Rst1.MoveLast '数据指针最后一行 Rst1.MoveFirst '数据指针第一行,这样的做的结果是让数据全部缓冲,可以读取正确的数据行数. End If GridDW.Clear GridDW.Rows = 1 GridDW.FormatString = "^ 序号|^ 学科 |^ 总分 |^ 差生分 |^ 及格分 |^ 优秀分|^ 尖子分 " Do While Not Rst1.EOF '循环开始,直到表结尾 GridDW.Rows = GridDW.Rows + 1 '加地行 GridDW.TextMatrix(GridDW.Rows - 1, 0) = Rst1.Fields(0) '用每一个字段进行填充.这种写法,严格依赖数据库结构, GridDW.TextMatrix(GridDW.Rows - 1, 1) = Rst1.Fields(1) '修改建议:在SQL命令中按照使用顺序写出字段列表来.不要使用默认顺序 GridDW.TextMatrix(GridDW.Rows - 1, 2) = Rst1.Fields(2) GridDW.TextMatrix(GridDW.Rows - 1, 3) = Rst1.Fields(3) GridDW.TextMatrix(GridDW.Rows - 1, 4) = Rst1.Fields(4) GridDW.TextMatrix(GridDW.Rows - 1, 5) = Rst1.Fields(5) GridDW.TextMatrix(GridDW.Rows - 1, 6) = Rst1.Fields(6) Rst1.MoveNext '下一条记录 Loop End Sub |
Private Sub ListKm()
Set Rst1 = New Recordset
sql = "select * from 学科表 order by 序号"
Rst1.Open sql, db, 1, 3
If Rst1.EOF Then
GridDW.Clear
GridDW.Rows = 1
GridDW.FormatString = "^ 序号|^ 学科 |^ 总分 |^ 差生分 |^ 及格分 |^ 优秀分|^ 尖子分 "
Exit Sub
Else
Rst1.MoveLast
Rst1.MoveFirst
End If
GridDW.Clear
GridDW.Rows = 1
GridDW.FormatString = "^ 序号|^ 学科 |^ 总分 |^ 差生分 |^ 及格分 |^ 优秀分|^ 尖子分 "
Do While Not Rst1.EOF
GridDW.Rows = GridDW.Rows + 1
GridDW.TextMatrix(GridDW.Rows - 1, 0) = Rst1.Fields(0)
GridDW.TextMatrix(GridDW.Rows - 1, 1) = Rst1.Fields(1)
GridDW.TextMatrix(GridDW.Rows - 1, 2) = Rst1.Fields(2)
GridDW.TextMatrix(GridDW.Rows - 1, 3) = Rst1.Fields(3)
GridDW.TextMatrix(GridDW.Rows - 1, 4) = Rst1.Fields(4)
GridDW.TextMatrix(GridDW.Rows - 1, 5) = Rst1.Fields(5)
GridDW.TextMatrix(GridDW.Rows - 1, 6) = Rst1.Fields(6)
Rst1.MoveNext
Loop
End Sub