[RESOLVED] Save Multiple data from listview to MSaccess
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Save Multiple data from listview to MSaccess

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    34

    [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..

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,947

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2005
    Posts
    1,074

    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 ...

  4. #4
    Join Date
    Feb 2013
    Posts
    34

    Re: Save Multiple data from listview to MSaccess

    Thanks Guys.. Its Work..

  5. #5
    Join Date
    Jul 2005
    Posts
    1,074

    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 ...

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center