Buongiorno,
ho utilizzato adox per creare un file .mdb.
Ma ora avrei bisogno un codice per creare tabelle dentro un file access.
Ecco il codice:
Imports System.Data.OleDb
Public Class Form1
Public dr As OleDbDataReader
Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\Users\ingfr\Desktop\test.mdb")
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Shows how to create an Access 2000 database and append tables, fields, indexes using ADOX. Don't forget
'a reference to ADOX (Microsoft ADO Ext. 2.x for DDL and Security)
Dim ADOXcatalog As New ADOX.Catalog
Dim ADOXtable As New ADOX.Table
Dim ADOXindex As New ADOX.Index
On Error GoTo errhandler
ADOXcatalog.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\Users\ingfr\Desktop\" + TextBox1.Text + ".mdb")
On Error Resume Next
ADOXcatalog.ActiveConnection =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& "C:\Users\ingfr\Desktop\" + TextBox1.Text + ".mdb"
'name table, append fields to table
ADOXtable.Name = "test"
ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("Attività", ADOX.DataTypeEnum.adVarWChar, 20)
'append tables to database
ADOXcatalog.Tables.Append(ADOXtable)
'internal index on two fields
'ADOXindex.Name = "TwoColumnsIndex" 'name of index
'ADOXindex.Columns.Append("LastName")
'ADOXindex.Columns.Append("ID")
ADOXtable.Indexes.Append(ADOXindex)
errhandler:
If Err.Number = -2147217897 Then
MsgBox("Database already exists")
ElseIf Err.Number <> 0 Then
MsgBox("Err " & Err.Description & "; operation not complete")
End If
ADOXtable = Nothing
ADOXindex = Nothing
ADOXcatalog = Nothing
End Sub