Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (12.85 KB, 3 trang )
[ Team LiB ]
Recipe 10.6 Creating a New Access Database
Problem
You need to create a new Microsoft Access database.
Solution
Use ActiveX Database Objects Extensions (ADOX) from .NET through COM interop.
You'll need a reference to Microsoft ADO Ext. 2.7 for DDL and Security from the COM
tab in Visual Studio .NET's Add Reference Dialog.
The sample code contains an event handler and a single method:
Button.Click
Allows the user to specify the filename for the new Access database and then calls
the CreateAccessDatabase( ) method in the sample to create the database.
CreateAccessDatabase( )
This method uses ADOX through COM interop to create the new Access database
having the specified filename.
The C# code is shown in Example 10-6
.
Example 10-6. File: CreateAccessDatabaseForm.cs
// Namespaces, variables, and constants
using System;
using System.Windows.Forms;
// . . .
private void createButton_Click(object sender, System.EventArgs e)
{
// Create the save file dialog object.
SaveFileDialog sfd = new SaveFileDialog( );
sfd.InitialDirectory = System.IO.Path.GetTempPath( );