|
本帖最后由 HUI0113 于 2024-3-15 11:42 编辑
chadwicko 发表于 2022-1-20 21:48
Public Sub 显示数据(strsql As String) '为ListView1设置各行数据
Dim i&, j&
On Error Resume ...
Public Sub 显示数据(strsql As String)
Dim i As Integer, j As Integer
On Error Resume Next ' 注意:在调试时可能需要移除或替换为更具体的错误处理
Set rs = New ADODB.Recordset
rs.Open strsql, cnn, adOpenKeyset, adLockOptimistic
With ListView1
.ListItems.Clear
If Not rs Is Nothing Then
If Not rs.EOF Then ' 确保记录集不为空
Do Until rs.EOF
.ListItems.Add , , CStr(rs.Fields(0).Value) ' 使用CStr转换为字符串
For j = 1 To rs.Fields.Count - 1
If j = 3 Then
' 确保rs.Fields(j).Value是日期或时间类型
.ListItems(.ListItems.Count).SubItems(j) = Format(CDate(rs.Fields(j).Value), "h:mm")
Else
.ListItems(.ListItems.Count).SubItems(j) = CStr(rs.Fields(j).Value)
End If
Next j
rs.MoveNext
Loop
End If
End If
End With
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Label2.Caption = "共找到 " & ListView1.ListItems.Count & " 条记录"
End Sub
|
|