ARTICLE

Using ADOX with ADO.NET

Posted by Dinesh Beniwal Articles | ADO.NET in VB.NET June 11, 2010
In this article I will explain using ADOX with ADO.NET.
 
Reader Level:

HTML clipboard

Microsoft ActiveX Data Objects Extensions for Data Definition Language and Security (ADOX) is an extension to ADO and provides an object model to manipulate data definition and security.
 
You can use ADOX in managed code in a pretty similar way to how you used an ADO recordset in the previous section. Just add a reference to ADOX type library using VS .NET's Add Reference option and use the namespace and its members as you would in unmanaged code.
 
To test this, create a newWindowsapplication. After that add a reference to the Microsoft ADO Ext. 2-7 for DLL and Security component to the project (see Figure 10-27).
 
Figure-10.27.jpg
 
Figure 10-27: Adding a reference to ADOX library
 
Now of you add reference in your project, you'll see that ADOX namespace is listed (see Figure 10-28).
 
Figure-10.28.jpg
 
Figure 10-28: ADOX namespace listed in project reference
 
Now the only thing you need to do is to use the namespace and its members. The ADOX classes should be available in your application after adding using ADOX to the project. ADOX provides objects that you can use to create databases, tables, and columns. The Catalog object represent a database and its create method creates a new database. The table object represents a database table. You can add columns to a table using the Columns collection's Append method.
 
Listing 10-7 creates a new Microsoft Access database called Test.mdb with the table MyTable and two columns, col1 and col2, in it.
 
Listing 10-7. Using ADOX from managed code
 

Public Class Form1

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        ' Create SQL and Connection strings

        Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; DataSource=c:\Test.mdb"

 

        Try

            ' Create a Catalog object

            Dim ct As New Catalog()

            ct.Create(ConnectionString)

 

            ' Create a table and two columns

            Dim dt As New Table()

            dt.Name = "MyTable"

            dt.Columns.Append("col1", DataTypeEnum.adInteger, 4)

            dt.Columns.Append("col2", DataTypeEnum.adVarWChar, 255)

 

 

            'Add table to the tables collection

            ct.Table.Append(DirectCast(dt, Object))

 

        Catch exp As Exception

            MessageBox.Show(exp.Message.ToString())

        End Try

    End Sub

End Class
 

Conclusion
 
Hope this article would have helped you in understanding using ADOX with ADO.NET. See other articles on the website also for further reference.

Login to add your contents and source code to this article
Article Extensions
Contents added by sadegh razavi on Jul 08, 2010
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor