-
February 9th, 2013, 12:16 PM
#1
[RESOLVED] Save Multiple data from listview to MSaccess
Hello Guys,,
I need Your Help I want to save my data in listview to my DB and This is My code to save data in listview
Code:
Private Sub save()
ListView1.ListItems.Add , , lblrp.Caption
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Caption
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbldate.Caption
End Sub
and this my code to Save Data in MSAccess Using Listview
Code:
Private Sub savetodailyrecord()
Dim lstSel As ListItem
Dim str As String
For Each lstSel In ListView1.ListItems
str = "Insert Into Dailyrecord (Receipt, BarCode, ProductName, Quantity, Price, TotalPrice, purchase_date) Values ('" & lstSel.Text & "', '" & lstSel.SubItems(1) & "','" & lstSel.SubItems(2) & "','" & lstSel.SubItems(3) & "','" & lstSel.SubItems(4) & "','" & lstSel.SubItems(5) & "'," & lstSel.SubItems(6) & ")"
acd.Execute str
Next
Call Purchase
ListView1.ListItems.clear
End Sub
But if my Data in Listview is only one.. My Program Run Correctly and Save the Data to DB, but in My listview had many data VB 6.0 Say: syntax error in the query expression
What shoul I Do?
Help Me guys..
-
February 9th, 2013, 04:13 PM
#2
Re: Save Multiple data from listview to MSaccess
Use Debug.Print str, then paste the contents of that into Access (SQL Editor). It will highlight on the first position of the first error. When there are no more errors, change VB6 to match EXACTLY.
You can EXPORT a table to a text file.
-
February 9th, 2013, 06:40 PM
#3
Re: Save Multiple data from listview to MSaccess
Use next way
Code:
Private Sub savetodailyrecord()
Dim X As Integer
Dim str As String
For X = 1 To ListView1.ListItems.Count
str = "Insert Into Dailyrecord (Receipt, BarCode, ProductName, Quantity, Price, TotalPrice, purchase_date) Values ('" & ListView1.ListItems(X).Text & "', '" & ListView1.ListItems(X).SubItems(1) & "','" & ListView1.ListItems(X).SubItems(2) & "','" & ListView1.ListItems(X).SubItems(3) & "','" & ListView1.ListItems(X).SubItems(4) & "','" & ListView1.ListItems(X).SubItems(5) & "'," & ListView1.ListItems(X).SubItems(6) & ")"
acd.Execute str
Next
Call Purchase
ListView1.ListItems.clear
End Sub
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
February 9th, 2013, 06:44 PM
#4
Re: Save Multiple data from listview to MSaccess
Also
It would be better if You do not use the word STR as a variable name
Because it's a Reserved Word
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
February 9th, 2013, 09:15 PM
#5
Re: Save Multiple data from listview to MSaccess
Thanks Guys.. Its Work..
Tags for this Thread
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
|