发点我通过EXCEL用VBA 取SQL数据库的数据后显示在LIST中的代码给你借鉴一下:
Private Sub UserForm_Initialize()
On Error Resume Next
myArray = Array("客户ID", "代码", "简称", "全称", "电话", "传真", "地址", "邮编", "税号", "账号", "联系人", "手机", "邮箱", "QQ", "Q代码", "Q简称")
MdbDate
Call LoadLVDm
Call LoadLVD
End Sub
Sub LoadLVD()
ListView1.ListItems.Clear
SQL = "Select * from 客户档案 Where 简称 Like '%" & Me.Q简称.value & "%' and 代码 Like '%" & Me.Q代码.value & "%'order by 简称;" ' Where 简称 Like '" & "*" & Me.Q简称.Value & "*" & "'
'Set rs = cnn.Execute(SQL)
'Print SQL
rs.Open SQL, cnn, 3, 2 ' adOpenKeyset, adLockOptimistic
For I = 1 To rs.RecordCount
With ListView1.ListItems.Add(, , rs.Fields("客户ID"))
.SubItems(1) = IIf(IsNull(rs.Fields("代码")), "", rs.Fields("代码"))
.SubItems(2) = IIf(IsNull(rs.Fields("简称")), "", rs.Fields("简称"))
.SubItems(3) = IIf(IsNull(rs.Fields("全称")), "", rs.Fields("全称"))
.SubItems(4) = IIf(IsNull(rs.Fields("电话")), "", rs.Fields("电话"))
.SubItems(5) = IIf(IsNull(rs.Fields("传真")), "", rs.Fields("传真"))
.SubItems(6) = IIf(IsNull(rs.Fields("地址")), "", rs.Fields("地址"))
.SubItems(7) = IIf(IsNull(rs.Fields("邮编")), "", rs.Fields("邮编"))
.SubItems(8) = IIf(IsNull(rs.Fields("税号")), "", rs.Fields("税号"))
.SubItems(9) = IIf(IsNull(rs.Fields("账号")), "", rs.Fields("账号"))
.SubItems(10) = IIf(IsNull(rs.Fields("联系人")), "", rs.Fields("联系人"))
.SubItems(11) = IIf(IsNull(rs.Fields("手机")), "", rs.Fields("手机"))
.SubItems(12) = IIf(IsNull(rs.Fields("邮箱")), "", rs.Fields("邮箱"))
.SubItems(13) = IIf(IsNull(rs.Fields("QQ")), "", rs.Fields("QQ"))
End With
rs.MoveNext
Next I
rs.Close
Set rs = Nothing
End Sub
Sub LoadLVDm()
With ListView1
.View = lvwReport
.FullRowSelect = True
.Gridlines = True
.FullRowSelect = True
.HideSelection = False
.LabelEdit = lvwManual
.ColumnHeaders.Add , , "客户ID", 0
.ColumnHeaders.Add , , "代码", 40
.ColumnHeaders.Add , , "简称", 50
.ColumnHeaders.Add , , "全称", 80
.ColumnHeaders.Add , , "电话", 60
.ColumnHeaders.Add , , "传真", 60
.ColumnHeaders.Add , , "地址", 110
.ColumnHeaders.Add , , "邮编", 0
.ColumnHeaders.Add , , "税号", 0
.ColumnHeaders.Add , , "账号", 0
.ColumnHeaders.Add , , "联系人", 50
.ColumnHeaders.Add , , "手机", 60
.ColumnHeaders.Add , , "邮箱", 0
.ColumnHeaders.Add , , "QQ", 0
End With
'添加一个图象到 ImageList1--图标 ImageList。
Dim imgX As ListImage
'Set imgX = ImageList1.ListImages.Add(, , LoadPicture(ThisWorkbook.Path & "\" & "1×25.bmp"))
'添加一个图象到 ImageList2--小图标 ImageList。
Set imgX = ImageList2.ListImages.Add(, , LoadPicture(ThisWorkbook.Path & "\" & "1×25.bmp"))
'若要将 ImageList 控件和 ListView 控件一起使用,必须将 Icons 和 SmallIcons 属性与特定的 ImageList 控件关联。
'ListView1.Icons = ImageList1
ListView1.SmallIcons = ImageList2
End Sub
连接好数据库后,用数据查询语句“”select * from 表名 where 条件”先读取出来,然后添加就行了。试试,不会了我再告诉你具体步骤啊
select * from 表名 WHERE 姓名 LIKE "刘%"
姓刘的就出来了。