VB中,Listview中的数据如何存入 access 的表中
我建了一个listview来显示ACCESS中的内容,我希望做的是,当我把LISTVIEW里面的内容修改或添加后,能存入ACCESS中.我在网上找到了这段代码,但怎么都没...
我建了一个listview来显示ACCESS中的内容, 我希望做的是,当我把LISTVIEW里面的内容修改或添加后,能存入ACCESS中.我在网上找到了这段代码,但怎么都没法用,请高手帮忙.
Dim index, k, j As Integer
Call OpenConn
sql = "select * from " & TName
rs.Open sql, cn, 1, 1
rs.MoveFirst
For Each Items In ListView1.ListItems '列出全部选项
Items.Selected = True
If index <= rs.RecordCount - 1 Then '表示修改没有新增
rs.Fields(0).Value = Items.Text
For k = 1 To Items.ListSubItems.Count
rs.Fields(i).Value = Items.ListSubItems.Item(i).Text
Next
rs.MoveNext
Else '表示新增
rs.AddNew
rs.Fields(0).Value = Items.Text
For j = 1 To Items.ListSubItems.Count
rs.Fields(j).Value = Items.ListSubItems.Item(j).Text
Next
End If
index = index + 1
Next
rs.MoveLast
rs.Update
Call CloseConn 展开
Dim index, k, j As Integer
Call OpenConn
sql = "select * from " & TName
rs.Open sql, cn, 1, 1
rs.MoveFirst
For Each Items In ListView1.ListItems '列出全部选项
Items.Selected = True
If index <= rs.RecordCount - 1 Then '表示修改没有新增
rs.Fields(0).Value = Items.Text
For k = 1 To Items.ListSubItems.Count
rs.Fields(i).Value = Items.ListSubItems.Item(i).Text
Next
rs.MoveNext
Else '表示新增
rs.AddNew
rs.Fields(0).Value = Items.Text
For j = 1 To Items.ListSubItems.Count
rs.Fields(j).Value = Items.ListSubItems.Item(j).Text
Next
End If
index = index + 1
Next
rs.MoveLast
rs.Update
Call CloseConn 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询