Quantcast
Viewing all articles
Browse latest Browse all 27215

Listview to access problems...

I have an inventory scanner I have made...

So it has 14 columns, and the amount of items range depending on which OU I scan in AD.

Basically lets say it has 70 computers in the list... It will insert into the database the same entry 70 times.

This is the code i'm using to iterate through the listview...

Code:

        Try
            For z As Integer = 0 To ListView1.Items.Count - 1
                ACCDB()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        Finally
            MessageBox.Show("Import was a success!", "Viola")
        End Try

and this is the importing work being done..

Code:

Public Sub ACCDB()

        Dim connect As New OleDb.OleDbConnection
        connect.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\awiles\Desktop\JOI Suite 8.0\database\joi.accdb"

        Dim sql As String = "INSERT INTO inventory VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

        Dim command As New System.Data.OleDb.OleDbCommand(sql, connect)
        command.Parameters.AddWithValue("@computer name", str(0).ToString)
        command.Parameters.AddWithValue("@description", str(1).ToString)
        command.Parameters.AddWithValue("@manufacturer", str(2).ToString)
        command.Parameters.AddWithValue("@model", str(3).ToString)
        command.Parameters.AddWithValue("@processors", str(4).ToString)
        command.Parameters.AddWithValue("@os type", str(5).ToString)
        command.Parameters.AddWithValue("@memory", str(6).ToString)
        command.Parameters.AddWithValue("@last logged on", str(7).ToString)
        command.Parameters.AddWithValue("@sn#", str(8).ToString)
        command.Parameters.AddWithValue("@ip", str(9).ToString)
        command.Parameters.AddWithValue("@mac", str(10).ToString)
        command.Parameters.AddWithValue("@admins", str(11).ToString)
        command.Parameters.AddWithValue("@location", str(12).ToString)
        command.Parameters.AddWithValue("@scanned", str(13).ToString)
        connect.Open()
        command.ExecuteNonQuery()
        connect.Close()

    End Sub


This works if I only have 1 item in the listview, but again... lists the same item over and over if it's multiple.

Any ideas?

Viewing all articles
Browse latest Browse all 27215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>