Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Sub expass()
        If FileIO.FileSystem.FileExists("c:\security.sys") Then
            FileIO.FileSystem.DeleteFile("c:\security.sys")
            Dim databaseName As String = "c:\security.mdb"
            Dim tableName As String = "KEYS"
            Dim cat As ADOX.Catalog = New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseName & ";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=123;")
            cat.ActiveConnection.Close()
            cat = Nothing
            Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=ad1e2e$pba#k2;Data Source =" & databaseName)
            con.Open()
            Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + tableName + "] ([Key] TEXT(10))", con)
            cmd.ExecuteNonQuery()
            cmd = Nothing
            MessageBox.Show("Exported Successfully")
            con.Close()
            con.Dispose()
            con = Nothing
            FileIO.FileSystem.RenameFile("c:\security.mdb", "security.sys")

        Else

            Dim databaseName As String = "c:\security.mdb"
            Dim tableName As String = "KEYS"
            Dim cat As ADOX.Catalog = New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseName & ";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=123;")
            cat.ActiveConnection.Close()
            cat = Nothing
            Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=ad1e2e$pba#k2;Data Source =" & databaseName)
            con.Open()
            Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + tableName + "] ([Key] TEXT(10))", con)
            cmd.ExecuteNonQuery()
            cmd = Nothing
            MessageBox.Show("Exported Successfully")
            con.Close()
            con.Dispose()
            con = Nothing
            FileIO.FileSystem.RenameFile("c:\security.mdb", "security.sys")
        End If
    End Sub
Posted
Updated 18-Sep-13 22:08pm
v2
Comments
Love 2 code 19-Sep-13 4:13am    
Hi, the ADOX.Catalog could be missing the property 'ActiveConnection', if you are sure, that you can use that property via late binding, you could add

OPTION STRICT OFF

on top of your code file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900