I am trying to create and populate a new access database. I found that I needed to include the reference to ADO extended in the com references. I includes the using ADOX; and the following if statement will successfully create the database.
if (!File.Exists("C:\\AccessDB\\NewMDB.mdb"))
{
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\AccessDB\\NewMDB.mdb;" + "Jet OLEDB:Engine Type=5");
MessageBox.Show("Database Created Successfully");
}
But I don't know how to add tables to this database. I found the following VB code and thought it would be easy enough to convert over but ran into some problems. Like the Columns append function requires a DataTypeEnum and I can't figure out how to create it. It also needed a columns object I specified the name but is there anything else I need to do with it If someone could just show me how you could do the same thing in c# that would be great thanks.
' BeginCreateTableVB
Sub Main()
On Error GoTo CreateTableError
Dim tbl As New Table
Dim cat As New ADOX.Catalog
' Open the Catalog.
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl
Debug.Print "Table 'MyTable' is added."
'Delete the table as this is a demonstration.
cat.Tables.Delete tbl.Name
Debug.Print "Table 'MyTable' is deleted."
'Clean up
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Set tbl = Nothing
Exit Sub
CreateTableError:
Set cat = Nothing
Set tbl = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndCreateTableVB

convert this VB code to C# help?
ytandeta
You could try creating the tables using SQL statements
Create table Users ...
This would give you a number of benefits, such as ease of manitenance and less code. Is there any particular reason why you want to do it this way
Sugan_Dave