Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

I get error message on my code can someone help me take a look

$
0
0

i am develop excel convert mdb system i get error message on below picture can someone help me take a look thanks

below is my code .

 If File.Exists("D:\B.mdb") Then
            File.Delete("D:\B.mdb")
        End If
        DBPath = "D:\B.mdb"

        ' create DB via ADOX if not exists
        ' NOTE: to use ADOX add reference to COM Microsoft ADO Ext. 2.6 for DDL and Security!
        If Not File.Exists(DBPath) Then
            Dim cat As New ADOX.Catalog()
            cat.Create(Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & DBPath)
            cat = Nothing

        End If

        conn = New OleDbConnection(Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & DBPath)
        conn.Open()

        Try
            Using cmd As New OleDbCommand("CREATE TABLE [test] ([id] COUNTER PRIMARY KEY, [num] INT, [name] MEMO, [no] INT);", conn)
                cmd.ExecuteNonQuery()
            End Using

        Catch ex As Exception
            If ex IsNot Nothing Then
                ex = Nothing

            End If
        End Try

        ' initialize the connect string
        Dim _filename As String = "D:\Book1.xls"
        '' Dim _conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & _filename & ";" & "Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
        Dim path As String
        path = "D:\Book1.xls"
        Dim _conn As String = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1;';"
        Dim _connection As OleDbConnection = New OleDbConnection(_conn)

        'Use OledbCommand object to select all the data from sheet1 and execute an ExecuteNonQuery to import data into test.mdb.
        Dim _command As OleDbCommand = New OleDbCommand()
        _command.Connection = _connection

        Try
            Using conn As New OleDbConnection(_conn)
                Using cmd As New OleDbCommand()
                    cmd.Connection = conn
                    cmd.CommandText = "INSERT INTO [MS Access;Database=" + DBPath + "].[test] SELECT * FROM [Sheet1$]"
                    conn.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
            '_command.CommandText = "SELECT * FROM [Sheet1$]"
            '_connection.Open()
            '_command.ExecuteNonQuery()
            '_connection.Close()
            MessageBox.Show("The import is complete!")

        Catch e1 As Exception
            MessageBox.Show("Import Failed, correct Column name in the sheet!" & Environment.NewLine & "Error Message:" & Environment.NewLine & e1.Message)
        End Try


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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