hello, i am trying to save data in my listview item to access database.. i am new to programming and i am currently working on a project i need to submit very soon, this is really urgent and i will be much happy if i could get assisted as soon as possible.. My listview has four columns Product name, Price, Quantity, Total.I want to save the data under these columns in to database with the same columns also. this is my code so far

                Dim i, c As String
                Dim a, b, d As String
                i = ListView1.Items.Count - 1
                While i >= 0
                    a = ListView1.Items.Item(i).Text
                    b = ListView1.Items.Item(i).SubItems.Item(1).Text
                    c = ListView1.Items.Item(i).SubItems.Item(2).Text
                    d = ListView1.Items.Item(i).SubItems.Item(2).Text
                    Dim strSQL As String
                    Dim objCmd As New OleDbCommand
                    strSQL = "INSERT INTO tblSalesData(ProductName, ProductPrice, Quantity, TotalPrice) VALUES ('" + a + "','" + b + "','" + c + "','" + d + "')"
                    Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ShopdbData.accdb;Jet OLEDB:Database Password=salesmanager")
                    objCmd = New OleDbCommand(strSQL, Con)
                    MsgBox("Transaction Successfully", MsgBoxStyle.Information, "The Shop Keeper")
                End While
            Catch eEndEdit As System.Exception
            End Try
3 Years
Discussion Span
Last Post by Dili1234

first off, you declared i as string, then you assign it an integer and compare it to an integer. Keeping Option Explicit On, helps to catch this kind of mismatch right away. Secondly, you've started a while loop based on the value of i, but you never change i so the loop will either exit without running or run forever. You probably need a conditional statement there,If i >= 0 Then

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.