Solved

mdb from schema

Posted on 2004-09-26
7
290 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now