'窗体设计:
'添加1个"ListView"控件 添加四个列头,分别是【列1:ID 列2:姓名 列3:电话 列4:地址】
'添加5个"text"控件
'-----------------------------------------
'先从数据库调出数据
'---------------------------
Dim ConnectionString As String
Set Conn = CreateObject("ADODB.Connection")
dbs = ”admin.mdb"'=数据库路径=
ConnectionString = "DBQ=" + dbs + ";Driver={Microsoft Access Driver (*.mdb)};pwd="
Conn.Open ConnectionString
''''''''''''''''''''''''''''''''''''''''''''''''''''
SQL = "select * from aaa"’=SQL语句:查询aaa表=
Set rs = Conn.Execute(SQL)
If Not rs.EOF Then'=排错语句,如果"aaa"表没有数据则跳过=
Do While Not rs.EOF‘=显示完所有记录后跳出循环=
Set ItmX = ListView1.ListItems.Add(, "key" & rs("ID"), rs("自动编号"))
ItmX.SubItems(1) = "" & rs("姓名")
ItmX.SubItems(2) = "" & rs("电话")
ItmX.SubItems(3) = "" & rs("地址")
rs.MoveNext
Loop
'----------------------------------
'获取点击"ListView"控件的一行数据
'用SelectedItem获取鼠标点击的行数
'SubItems获取列
'----------------------------------
text1=”aaa“
text2= Main.ListView1.SelectedItem.SubItems(0)
text3= Main.ListView1.SelectedItem.SubItems(1)
text4= Main.ListView1.SelectedItem.SubItems(2)
text5= Main.ListView1.SelectedItem.SubItems(3)
'-------------------------------------
'如果你还需要向数据库添加数据用下面的模块
'-------------------------------------
Dim ConnectionString As String
Set Conn = CreateObject("ADODB.Connection")
dbs = ”admin.mdb“'=数据库路径=
ConnectionString = "DBQ=" + dbs + ";Driver={Microsoft Access Driver (*.mdb)};pwd="
Conn.Open ConnectionString
exec = "insert into aaa(ID,名称,电话,地址)values('" + text1 + "','" + text2 + "','" + text3 + "','" + text4 + "')"
Conn.Execute exec