|
-
Mar 16th, 2009, 04:15 AM
#1
Thread Starter
Junior Member
listbox-mstable
no nid
5 1322
6
7
8
9
no nid
6 66
8
1
i want to add item to msaccess like this.
here the no field contains listitem.
i want codings in vb6
-
Mar 16th, 2009, 06:10 AM
#2
Re: listbox-mstable
Try this
Code:
'add a reference to the Microsoft ActiveX Data Object Library
Private Sub Command1_Click
Dim ADOCn As ADODB.Connection
Dim ConnString As String
Dim sSQL As String
Dim i As Long
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\yourdatabase.mdb;" & _
"Persist Security Info=False"
Set ADOCn = New ADODB.Connection
ADOCn.ConnectionString = ConnString
ADOCn.Open ConnString
For i = 0 To List1.ListCount - 1
sSQL = "INSERT INTO yourtablename (fieldname) "
sSQL = sSQL & "VALUES('" List1.List(i) & "' ")
ADOCn.Execute sSQL
Next
ADOCn.Close
Set ADOCn = Nothing
End Sub
-
Mar 17th, 2009, 12:50 AM
#3
Thread Starter
Junior Member
Re: listbox-mstable
thanks for ur reply.
i try this codings
error appear in this line
sSQL = sSQL & "VALUES('" List1.List(i) & "' ")
ADOCn.Execute sSQL
-
Mar 17th, 2009, 05:59 AM
#4
Re: listbox-mstable
And what would that error be?
-
Mar 17th, 2009, 10:55 AM
#5
Thread Starter
Junior Member
Re: listbox-mstable
syntax error in
sSQL = sSQL & "VALUES(' " List1.List(i) & " ' ")
---------------
witht hanks
amala
-
Mar 17th, 2009, 10:59 AM
#6
Re: listbox-mstable
Try this
Code:
sSQL = sSQL & "VALUES('" & List1.List(i) & "' "
-
Mar 17th, 2009, 11:42 PM
#7
Thread Starter
Junior Member
Re: listbox-mstable
i try this code
error
------
syntax error "insert into statement"
ADOCn.Execute sSQL //-error
----------
-
Mar 18th, 2009, 06:13 AM
#8
Re: listbox-mstable
Do this
Code:
For i = 0 To List1.ListCount - 1
sSQL = "INSERT INTO yourtablename (fieldname) "
sSQL = sSQL & "VALUES('" & List1.List(i) & "' "
Debug.Print sSQL '<========= add this line
' ADOCn.Execute sSQL
Next
After you run it, open the Immediate window and copy 'n paste what is there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|