Hola!
A través de este código vacío una tabla en ACCESS, el problema es que tarda mucho... y no me explico porque, aunque este vacía tarda de 3 a 5 minutos para terminar.
Estoy haciendo algo mal?? El archivo de access esta en el PC local.
Dim Connection As New System.Data.OleDb.OleDbConnection
        Dim Command As New System.Data.OleDb.OleDbCommand
        Connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\yo\Desktop\db.accdb"
        Command.Connection = Connection
        Connection.Open()


        Try
            Dim increment As Integer = 0
            Dim str1 As String
            For x As Integer = 0 To DataGridView1.Rows.Count - 2
                increment = increment + 1
                If increment > ToolStripProgressBar1.Maximum Then
                    increment = ToolStripProgressBar1.Maximum
                End If
                str1 = "DELETE saldi.* FROM saldi"
                Dim com As New OleDb.OleDbCommand(str1, Connection)
                com.ExecuteNonQuery()
                ToolStripProgressBar1.Value = increment
            Next
            Connection.Close()
            MessageBox.Show("Tabla vacia! '" + TimeOfDay + "'", "Query Vacia Tabla", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As OleDb.OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
        End Try
Gracias!
Saludos!
Si... es verdad... que tonto! luego de 9 horas con esto me estoy perdiendo... El For no tiene ningún sentido y quitandolo solucione el problema. Me confundí con otra parte del código y mezcle las cosas:
Dim Connection As New System.Data.OleDb.OleDbConnection
        Dim Command As New System.Data.OleDb.OleDbCommand
        Connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\yo\Desktop\db.accdb"
        Command.Connection = Connection
        Connection.Open()

        Try
            Dim increment As Integer = 0
            Dim str1 As String
            For x As Integer = 0 To DataGridView1.Rows.Count - 2
                increment = increment + 1
                If increment > ToolStripProgressBar1.Maximum Then
                    increment = ToolStripProgressBar1.Maximum
                End If
                str1 = "INSERT INTO saldi(ItemCode,ItemName,Periodo,Giacenza,Previsione,Saldo)values('" + DataGridView1.Rows(x).Cells(1).Value.ToString + "','" + CleanInput(DataGridView1.Rows(x).Cells(2).Value.ToString) + "','" + DataGridView1.Rows(x).Cells(3).Value.ToString + "','" + DataGridView1.Rows(x).Cells(4).Value.ToString + "','" + DataGridView1.Rows(x).Cells(5).Value.ToString + "','" + DataGridView1.Rows(x).Cells(0).Value.ToString + "')"
                Dim com As New OleDb.OleDbCommand(str1, Connection)
                com.ExecuteNonQuery()
                ToolStripProgressBar1.Value = increment
            Next
            Connection.Close()
            MessageBox.Show("OK! '" + TimeOfDay + "'", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As OleDb.OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
        End Try
El metodo es correcto? Aqui necesito recorrer cada renglon para copiar los datos uno por uno en la tabla de Access, asi que el For supongo que esta bien, pero de todos modos creo va lento... tengo la sensación, que por mas que funcione, hay algo que no esta bien
Gracias y saludos!
Responder

Volver a “VB/.NET”