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

Try
                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")
                    Con.Open()
                    objCmd = New OleDbCommand(strSQL, Con)
                    objCmd.ExecuteNonQuery()
                    Con.Close()
                    MsgBox("Transaction Successfully", MsgBoxStyle.Information, "The Shop Keeper")
                End While
            Catch eEndEdit As System.Exception
                System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
            End Try

Recommended Answers

All 2 Replies

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

there should bean increment on i
i=i+1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.