make dataset in memory then save as access DB

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
i know how to make a dataset in memory and i've got several that in the programs the dataset's are simply saved as *.xml files but i was wondering how to (in memory) take that database and connect it to an access DB (which doesnt exist) so the app creates the actual database file on the HDD

i know i gotta make a connection, i know how to do that but what do i do about the data adapter?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
ADO doesn't provide a way to create Access DataBases. You can however create a dataBase with interopt using ADOX.
Add a reference to 'Microsoft ADO Ext. 2.7 for DLL and Security' under the COM tab.

Here's some sample code:
VB.NET:
Dim cat As New ADOX.Catalog()
Dim tbl As New ADOX.Table()
Try
    'Make sure the folder provided in the path exists.
    Dim sCreateString As String
    sCreateString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
       DatabaseFullPath
    'create the database
    cat.Create(sCreateString)
    'name the table
    tbl.Name = "NewTable"
    'append some columns
    tbl.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
    tbl.Columns.Append("Name", ADOX.DataTypeEnum.adVarWChar, 40)
    'make the ID column a Primary Key()
    tbl.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "ID")
    'append the table
    cat.Tables.Append(tbl)
Catch Excep As System.Runtime.InteropServices.COMException
    MessageBox.Show(Excep.Message)
Finally
    cat = Nothing
    tbl = Nothing
End Try
You could programatically loop through the tables in the dataset adding the tables to the catalog (as well as the fields in each table, adding as columns) then update the new database with the dataset.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
thanx, i'll play with this within the next couple of days
 
Top Bottom