Imports Microsoft.Office.Interop.Access.Dao
Public Class clsAccessCreator
Public Function CreateAccessFile(ByVal strPathFile As String) As Boolean
Dim res As Boolean = True
Try
Dim AccessDatabaseEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
Dim AccessDatabase As Microsoft.Office.Interop.Access.Dao.Database
AccessDatabase = AccessDatabaseEngine.CreateDatabase(strPathFile, LanguageConstants.dbLangGeneral, DatabaseTypeEnum.dbVersion120)
AccessDatabase.Close()
Using conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
" Data Source=" & strPathFile & ";Persist Security Info=False;")
'Create tables
Using cmd As New OleDb.OleDbCommand("CREATE TABLE Conexiones ( " & _
"Id int NOT NULL," & _
"Orden int NOT NULL," & _
"BasedeDatos NVarchar(255) NOT NULL," & _
"CadenaConexion text NOT NULL," & _
"CONSTRAINT Id_PK PRIMARY KEY(Id)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Using
Using cmd As New OleDb.OleDbCommand("CREATE TABLE Tablas ( " & _
"Id int NOT NULL ," & _
"Orden int NOT NULL," & _
"BasedeDatos NVarchar(255) NOT NULL," & _
"NombreTabla NVarchar(255) NOT NULL," & _
"Condicion Text," & _
"CONSTRAINT Id_PK PRIMARY KEY(Id)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Using
'Insert values
Try
'Conexiones
Dim Sql As String
Sql = "INSERT INTO Conexiones(Id,Orden,BasedeDatos,CadenaConexion) VALUES(1, 1,'Cont','Data Source=.\;Initial Catalog=Cont;Integrated Security=SSPI;');"
Dim cmdI As New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
Sql = "INSERT INTO Conexiones(Id,Orden,BasedeDatos,CadenaConexion) VALUES(2, 2,'Gest','Data Source=.\;Initial Catalog=Gest;User ID=sa;Password=1234;');"
cmdI = New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
'Operaciones
Sql = "INSERT INTO Tablas(Id,Orden,BasedeDatos,NombreTabla,Condicion) VALUES(1, 1,'Cont','Table_1',NULL);"
cmdI = New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
Sql = "INSERT INTO Tablas(Id,Orden,BasedeDatos,NombreTabla,Condicion) VALUES(2, 2,'Cont','Table_2',NULL);"
cmdI = New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
Sql = "INSERT INTO Tablas(Id,Orden,BasedeDatos,NombreTabla,Condicion) VALUES(3, 3,'Gest','Table_1',NULL);"
cmdI = New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
Sql = "INSERT INTO Tablas(Id,Orden,BasedeDatos,NombreTabla,Condicion) VALUES(4, 4,'Gest','Table_2',NULL);"
cmdI = New OleDb.OleDbCommand(Sql, conn)
cmdI.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Using
Catch ex As Exception
MsgBox(ex.Message)
Debug.WriteLine(ex.Message)
End Try
Return res
End Function
End Class
Suscribirse a:
Enviar comentarios (Atom)
VBA Access. Redondeo de números decimales con el método medio redondeo. Alternativa a la función Round (bankers round)
Private Function Redondeo(ByVal Numero As Variant, ByVal Decimales As Integer) As Double 'Aplica método medio redondeo (half round ...
-
Option Compare Database Option Explicit '***************************** ' 'Ejemplo de uso ' 'selecciona 1 ficher...
-
Option Compare Database Option Explicit 'Zip / UnZip file or folder 'http://www.codekabinett.com/rdumps.php?Lang=2&targetDoc...
No hay comentarios:
Publicar un comentario