Solved

mdb from schema

Posted on 2004-09-26
7
292 Views
Last Modified: 2012-08-13
I have a schema.xsd that layouts multiple tables in my strong-typed dataset. I want to save this dataset to a completely new .mdb file with some VB code. Anyone know how?
0
Comment
Question by:srcalc
  • 4
  • 3
7 Comments
 

Accepted Solution

by:
User111111 earned 125 total points
ID: 12155291
I'm not sure if this would work for dynamic db schemas, but it might work if you need to continually recreate a database from the same schema.

use adox to create your database based on your schema file.  you could parse the schema programatically or you could manually read it and replace the below values....

Private Sub cmdCreate_Click()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As ADODB.Connection

    ' Delete the database if it already exists.
    On Error Resume Next
    Kill txtDatabaseName.Text
    On Error GoTo 0

    ' Create the new database.
    Set cat = New ADOX.Catalog
    cat.Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & txtDatabaseName.Text & ";"

    ' Create a new table.
    Set tbl = New ADOX.Table
    tbl.Name = "TestTable"
    tbl.Columns.Append "FirstName", adVarWChar, 40
    tbl.Columns.Append "LastName", adVarWChar, 40
    tbl.Columns.Append "Birthdate", adDate
    tbl.Columns.Append "Weight", adInteger
    cat.Tables.Append tbl

    ' Connect to the database.
    Set con = cat.ActiveConnection

    ' Insert records.
    con.Execute "INSERT INTO TestTable VALUES ('Andy', " & _
        "'Able', '1 Jan 1980', '150')"
    con.Execute "INSERT INTO TestTable VALUES ('Betty', " & _
        "'Baker', #2/22/1990#, 70)"

    ' Close the database connection.
    con.Close
    Set con = Nothing
    Set tbl = Nothing
    Set cat = Nothing

    MsgBox "Done"
End Sub
0
 
LVL 4

Author Comment

by:srcalc
ID: 12155415
is that vb .net? I cant seem to find the classes that you used:

Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As ADODB.Connection
0
 

Expert Comment

by:User111111
ID: 12155449
add a reference to your project, Microsoft ADO Ext. 2.6 for DLL and Security or something similar if you don't have that exact version.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 4

Author Comment

by:srcalc
ID: 12155597
OK, is it possible to do with System.Data.OLeDB so I don't have to use a reference?
0
 

Expert Comment

by:User111111
ID: 12156276
nope, there is no current built-in way to dynamically make a new access db in vb.net
0
 
LVL 4

Author Comment

by:srcalc
ID: 12156287
ok let me fool around with that code and get back to you
0
 
LVL 4

Author Comment

by:srcalc
ID: 12229010
OK thanks for your input!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question