vb2008中,怎么把listbox中的内容逐条写到数据库(access)中

请附上详细代码,不胜感激,哭谢……
2024-11-16 00:20:07
推荐回答(2个)
回答1:

首先,编写一个写入数据到数据库的函数,比如
Function AddToDb(Byval s as string)
......
End Function

然后再for i=0 to list1.listcount-1来把每一项list1.list(i)添加到数据库中

回答2:

Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim SqlStr As String
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=123"
For i = 0 To List1.ListCount - 1
cn.Execute "INSERT INTO 会员消费 (会员编号) VALUES ('" & List1.List(i) & "');"
Next i
cn.Close
Set cn = Nothing
End Sub