Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: specific access provider with ado or adox


Message #1 by "Paulo Roberto Campos de Morais Lobo" <prlobo@i...> on Tue, 23 Jan 2001 11:56:20 est
helo, folks!



Can somebody help me?.. 



How can I use a specific access provider with ADO or ADOX 

to generate an MDB file?



Thank you so much for the help and time!.. 

[[ ]]'S paulo

Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 23 Jan 2001 15:49:09 +0100
Hi there,



The following procedure creates a new Access database through AdoX with VB.

It shouldn't be too hard to re-write it for ASP: just remove the strong 

typing and you are almost there. And I think that you should change Set 

tblNew = New ADOX.Table into Set tblNew = Server.CreateObject.....



HtH



Imar



Usage:



         CreateAccessTable("c:\testDatabase.mdb")



<SUB>

Sub CreateAccessTable(strDBPath As String)

    Dim catDB As ADOX.Catalog

    Dim tblNew As ADOX.Table

    Set catDB = New ADOX.Catalog

    ' Open the catalog.

    catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

       "Data Source=" & strDBPath

    Set tblNew = New ADOX.Table

    ' Create a new Table object.

     With tblNew

         .Name = "Contacts"

         ' Create fields and append them to the

         ' Columns collection of the new Table object.

         With .Columns



           .Append "ID", adInteger

            .Append "FirstName", adVarWChar

            .Append "LastName", adVarWChar

            .Append "Phone", adVarWChar

            .Append "Notes", adLongVarWChar

         End With



         With !FirstName

             .Attributes = adColNullable

         End With

     End With





     ' Add an extra column, with all settings at once.

     ' Note: You can't add attributes at the same time here.

     ' An error will occurr if you try anyway.

     Dim col As ADOX.Column

     Set col = New ADOX.Column

     With col

         .ParentCatalog = catDB

         .Type = adInteger

         .Name = "ID2"

         .Properties("Autoincrement") = True

     End With

     tblNew.Columns.Append col



    ' Add the new Table to the Tables collection of the database.

    catDB.Tables.Append tblNew

    Set catDB = Nothing

End Sub

</sub>



At 11:56 AM 1/23/2001 -0500, you wrote:

>helo, folks!

>

>Can somebody help me?..

>

>How can I use a specific access provider with ADO or ADOX

>to generate an MDB file?

>

>Thank you so much for the help and time!..

>[[ ]]'S paulo



Message #3 by John Pirkey <mailjohnny101@y...> on Tue, 23 Jan 2001 07:07:24 -0800 (PST)
You can't do it with regular ADO - you have to use ADOX.  Try this:



Dim oCatalog as ADOX.Catalog

 

Set oCatalog = New ADOX.Catalog

Call oCatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" App.Path &

"\test1.mdb;")



you're done - there are no tables or anything, but the mdb file is there.  Note,

this will create an Access 2000 database - if you want an Access 97 database, use

3.51 instead of 4.0 in the provider.



hope this helps,



john



--- Paulo Roberto Campos de Morais Lobo <prlobo@i...> wrote:

> helo, folks!

> 

> Can somebody help me?.. 

> 

> How can I use a specific access provider with ADO or ADOX 

> to generate an MDB file?

> 

> Thank you so much for the help and time!.. 

> [[ ]]'S paulo

> 

---------------------------- 

John Pirkey 

MCSD 

John@S... 

http://www.stlvbug.org

Message #4 by Imar Spaanjaars <Imar@S...> on Tue, 23 Jan 2001 16:13:59 +0100
Think before you write, Imar. Sorry, my previous code only showed half of 

what's needed. It only showed the method to insert a new table into an 

existing Access database. It didn't show how to create the database itself, 

so here it is again, this time complete.



As a bonus, to compensate for my stupidity, I re-wrote the example in ASP:





Please let me know if this works for you.



Imar







<CODE>

Dim sDatabaseName

sDatabaseName = "C:\testDatabase.mdb"

' First call the Create Database method

CreateAccessDatabase sDatabaseName

' Then add a table and columns to this database

CreateAccessTable sDatabaseName



Sub CreateAccessDatabase(strDBPath)

         Dim catNewDB ' As ADOX.Catalog

         Set catNewDB = Server.CreateObject("ADOX.Catalog")

         catNewDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _

                 "Data Source=" & strDBPath & _

                 ";Jet OLEDB:Engine Type=5;"

                         ' Engine Type=5 = Access 2000 Database

                         ' Engine Type=4 = Access 97 Database

         Set catNewDB = Nothing

End Sub





Sub CreateAccessTable(strDBPath)

         Dim catDB ' As ADOX.Catalog

         Set catDB = Server.CreateObject("ADOX.Catalog")

         Dim tblNew  ' As ADOX.Table

         Set tblNew = Server.CreateObject("ADOX.Table")

         ' Open the catalog.

         catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

                 "Data Source=" & strDBPath

         ' First Create an Autonumber column, called ID. This is just for 

demonstration.

         ' I could have done this below with all the other columns as well

         Dim col ' As ADOX.Column

         Set col = Server.CreateObject("ADOX.Column")

         With col

                 .ParentCatalog = catDB

                         .Type = adInteger

                 .Name = "ID"

                 .Properties("Autoincrement") = True

         End With

         tblNew.Columns.Append col

         ' Now add the rest of the columns

         With tblNew

                 .Name = "Contacts"

                 ' Create fields and append them to the

                 ' Columns collection of the new Table object.

                         With .Columns

                                 .Append "aNumberColumn", adInteger

                                    .Append "FirstName", adVarWChar

                                    .Append "LastName", adVarWChar

                                    .Append "Phone", adVarWChar

                                    .Append "Notes", adLongVarWChar

                         End With

                         Dim adColNullable       ' Is not defined in 

adovbs.inc, so do it by had. Other option is:

                                                         'adColFixed with a 

value of 1

                         adColNullable = 2

                         With .Columns("FirstName")

                                 .Attributes = adColNullable

                         End With

         End With

         ' Add the new Table to the Tables collection of the database.

         catDB.Tables.Append tblNew

         Set Col = Nothing

         Set tblNew = Nothing

         Set catDB = Nothing

End Sub

</code>



At 11:56 AM 1/23/2001 -0500, you wrote:

>helo, folks!

>

>Can somebody help me?..

>

>How can I use a specific access provider with ADO or ADOX

>to generate an MDB file?

>

>Thank you so much for the help and time!..

>[[ ]]'S paulo




  Return to Index