发现我这段代码里的movelast和movefist并不能把记录移到最后面或者最开始的位置
代码的部分如下,哪位高手帮我看看,谢谢
'数据库的读取和显示
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim DbPath As String
DbPath = App.Path
If Right(DbPath, 1) <> "\" Then DbPath = DbPath & "\"
Dim ConnStr As String
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath & "data\ssqyzh.mdb"
conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "select * from db1"
rs.Open SQL, conn, adOpenKeyset
rs.MoveLast
'表1的设置
With MSHFlexGrid1
.Clear
.Top = 900
.Left = 0
.FillStyle = 1
'第一行高度
.RowHeight(0) = 360
'列的宽度
.ColWidth(0) = 450
.ColWidth(1) = 950
.ColWidth(2) = 1300
.ColWidth(3) = 1800
.ColWidth(4) = 450
.ColWidth(5) = 800
.ColWidth(6) = 800
'表头命名和居中
.ColAlignmentFixed = 4
.TextMatrix(0, 0) = "1"
.TextMatrix(0, 1) = "2"
.TextMatrix(0, 2) = "3"
.TextMatrix(0, 3) = "4"
.TextMatrix(0, 4) = "5"
.TextMatrix(0, 5) = ""
Dim i, j, k, n As Integer
'表1数据库的读取及grid赋值(除第一列)
For k = 1 To 20
.TextMatrix(k, 1) = rs.Fields(0).Value
.TextMatrix(k, 2) = rs.Fields(1).Value
.TextMatrix(k, 3) = rs.Fields(2).Value
.TextMatrix(k, 4) = rs.Fields(3).Value
rs.MovePrevious
代码的部分如下,哪位高手帮我看看,谢谢
'数据库的读取和显示
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim DbPath As String
DbPath = App.Path
If Right(DbPath, 1) <> "\" Then DbPath = DbPath & "\"
Dim ConnStr As String
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath & "data\ssqyzh.mdb"
conn.Open ConnStr
rs.CursorLocation = adUseClient
SQL = "select * from db1"
rs.Open SQL, conn, adOpenKeyset
rs.MoveLast
'表1的设置
With MSHFlexGrid1
.Clear
.Top = 900
.Left = 0
.FillStyle = 1
'第一行高度
.RowHeight(0) = 360
'列的宽度
.ColWidth(0) = 450
.ColWidth(1) = 950
.ColWidth(2) = 1300
.ColWidth(3) = 1800
.ColWidth(4) = 450
.ColWidth(5) = 800
.ColWidth(6) = 800
'表头命名和居中
.ColAlignmentFixed = 4
.TextMatrix(0, 0) = "1"
.TextMatrix(0, 1) = "2"
.TextMatrix(0, 2) = "3"
.TextMatrix(0, 3) = "4"
.TextMatrix(0, 4) = "5"
.TextMatrix(0, 5) = ""
Dim i, j, k, n As Integer
'表1数据库的读取及grid赋值(除第一列)
For k = 1 To 20
.TextMatrix(k, 1) = rs.Fields(0).Value
.TextMatrix(k, 2) = rs.Fields(1).Value
.TextMatrix(k, 3) = rs.Fields(2).Value
.TextMatrix(k, 4) = rs.Fields(3).Value
rs.MovePrevious
关健是看你SQL语句返回数据是怎么样排序的,看你的问题应该在SQL语句中加order by排序你要的结果
我加个order by 试试看,谢谢
结果,运行时在
.TextMatrix(k, 3) = rs.Fields(2).Value
这里发生了无效使用 null不加order by 用的好好的啊我把.TextMatrix(k, 3) = rs.Fields(2).Value
.TextMatrix(k, 4) = rs.Fields(3).Value删掉后倒正常按我的要求从最后一条记录显示倒数20条数据,就是字段3.4不显示了,什么原因啊
可在 加入以下语句
if (rs.Fields(字段2).Value isNULL) then
TextMatrix(k, 3) = '写入为空的内容,
elseTextMatrix(k, 3) = rs.Fields(字段2).Value
endif
.TextMatrix(k, 3) = rs.Fields(2).Value & vbnullstring