Creating a New Access Database
Số trang: 3
Loại file: pdf
Dung lượng: 12.85 KB
Lượt xem: 13
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ 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. Youll need a reference to Microsoft ADO Ext. 2.7 for DDL and Security from the COM tab in Visual Studio
Nội dung trích xuất từ tài liệu:
Creating a New Access Database[ Team LiB ]Recipe 10.6 Creating a New Access DatabaseProblemYou need to create a new Microsoft Access database.SolutionUse ActiveX Database Objects Extensions (ADOX) from .NET through COM interop.Youll need a reference to Microsoft ADO Ext. 2.7 for DDL and Security from the COMtab in Visual Studio .NETs 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 constantsusing 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( ); // Set the filter for Access databases. sfd.Filter = Microsoft Access (*.mdb)|*.mdb; // Open the dialog. if (sfd.ShowDialog( ) == DialogResult.OK) { // Of OK selected, create the Access database. String fileName = sfd.FileName; try { CreateAccessDatabase(fileName); MessageBox.Show(Microsoft Access database + fileName + created., Create Access Database, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (System.Exception ex) { MessageBox.Show(Could not create database + fileName + . + ex.Message, Create Access Database, MessageBoxButtons.OK, MessageBoxIcon.Error); } }}private void CreateAccessDatabase(String fileName){ String connectString = @Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + fileName + ;; // Use ADOX to create the Access database. ADOX.Catalog cat = new ADOX.Catalog( ); try { cat.Create(connectString); } finally { cat = null; }}DiscussionADO Extensions for DDL and Security (ADOX) extends the ADO objects andprogramming model with objects for schema creation and modification, and for security.ADOX is used to programmatically access and manipulate the objects in a database.You can use ADOX from .NET through COM interop to create a new Microsoft Accessdatabase. Use the Create( ) method of the ADOX.Catalog object, passing a connectionstring for the new Access database as the argument.[ Team LiB ]
Nội dung trích xuất từ tài liệu:
Creating a New Access Database[ Team LiB ]Recipe 10.6 Creating a New Access DatabaseProblemYou need to create a new Microsoft Access database.SolutionUse ActiveX Database Objects Extensions (ADOX) from .NET through COM interop.Youll need a reference to Microsoft ADO Ext. 2.7 for DDL and Security from the COMtab in Visual Studio .NETs 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 constantsusing 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( ); // Set the filter for Access databases. sfd.Filter = Microsoft Access (*.mdb)|*.mdb; // Open the dialog. if (sfd.ShowDialog( ) == DialogResult.OK) { // Of OK selected, create the Access database. String fileName = sfd.FileName; try { CreateAccessDatabase(fileName); MessageBox.Show(Microsoft Access database + fileName + created., Create Access Database, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (System.Exception ex) { MessageBox.Show(Could not create database + fileName + . + ex.Message, Create Access Database, MessageBoxButtons.OK, MessageBoxIcon.Error); } }}private void CreateAccessDatabase(String fileName){ String connectString = @Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + fileName + ;; // Use ADOX to create the Access database. ADOX.Catalog cat = new ADOX.Catalog( ); try { cat.Create(connectString); } finally { cat = null; }}DiscussionADO Extensions for DDL and Security (ADOX) extends the ADO objects andprogramming model with objects for schema creation and modification, and for security.ADOX is used to programmatically access and manipulate the objects in a database.You can use ADOX from .NET through COM interop to create a new Microsoft Accessdatabase. Use the Create( ) method of the ADOX.Catalog object, passing a connectionstring for the new Access database as the argument.[ Team LiB ]
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Creating a New Access DatabaseTài liệu liên quan:
-
52 trang 434 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 321 0 0 -
74 trang 304 0 0
-
96 trang 299 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 293 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 286 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 270 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 270 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0