Error » Certification & Programming center Error !! » Programming tutorials » Data Access Layer For Microsoft Access Databases

Programming tutorials All Knowledge Info and links to posted here

Post New Thread Reply
  Data Access Layer For Microsoft Access Databases
LinkBack Thread Tools Display Modes
Old 03-Jan-2007, 10:19 PM   #1 (permalink)
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Data Access Layer For Microsoft Access Databases

This multi installment article will provide instructions and source code you can use to create a data access layer (DAL) for Microsoft Access databases. Along the way the article will explain when a DAL may be appropriate and some of the roles ADO.NET and Visual Studio data technologies can play in a DAL.
This first installment provides instructions and a downloadable example that can be used to create a basic class library (DLL) that will be extended in future installments to become a data access layer for Microsoft Access databases.
Instructions for Creating a Class Library for a Data Access Layer
A. Create a new Visual Basic Visual Studio 2005 Windows Forms solution.
B. Add a Visual Studio 2005 Class project to the Visual Studio solution.
1. From the File menu select Add -> New Project...

2. The 'Add New Project' window will open.

3. In the 'Project types:' section of the window select "Visual Basic".


4. In the 'Templates:' section of the window select "Class Library".


5. In the 'Name:' text box enter 'DataService'.


6. Click the 'OK' button.


7. A class library project named DataService is added to the solution, 'Class1' is created in the library, and 'Class1' opens in the code editor.


8. Close 'Class1'


9. Delete 'Class1' from the DataService project.

C. Add a component class to the DataService project.
1. Right-click the 'DataService' project in the 'Solution Explorer' panel and select Add -> New Item...

2. The 'Add New Item - DataService' window will open.


3. In the 'Templates' section of the window select 'Component Class'.


4. In the 'Name:' text box enter 'DAL'.



5. Click the 'OK' button.


6. A component class named 'DAL' is added to the DataService project and the 'DAL' component designer opens.


7. Close the 'DAL' component designer.


D. Add one or more data sources to the DataService project.
1. Add a data source to the DataService project

a. Click the DataService project in the Visual Studio solution to make sure it is selected.


b. From the Visual Studio 'Data' menu select 'Add New Data Source...'


c. The 'Data Source Configuration Wizard' window will open.


d. In the 'Where will the application get its data from?' section of the window click 'Database'.



e. Click the 'Next' button.


f. The 'Choose Your Data Connection' step window of the wizard will open.



g. Click the 'New Connection' button.


h. The 'Add Connection' window will open.



i. Make sure the 'Data Source' label reads 'Microsoft Access Database File (OLE DB)'.

(1) If it doesn't click the 'Change...' button.


(2) The 'Change Database' window will open.


(3) Double-click 'Microsoft Access Database' in the 'Data source:' section of the window.


j. Click the 'Browse...' button.


k. The 'Select Microsoft Access Database File' dialog will open. Navigate to an Access Database (.mdb) file.



l. Double-click the file. You are returned to the 'Add Connection' window.


m. Click the 'Test Connection' button.


n. If the test is successful, click the 'OK' button. Otherwise, backup and try again.


o. You will be returned to the 'Choose Your Data Connection' step window of the wizard.


p. Click the 'Next...' button.


q. A dialog box will open. The dialog asks if you want to add a copy of the database to the project.



r. Click the 'Yes' button.


s. The 'Save Connection String to the Application Configuration File' step window of the wizard opens.



t. Click the 'Next...' button.


u. The 'Choose Your Database Objects' step window of the wizard opens.



v. In the "Which database objects do you want in your dataset?' section use the tree view control to make the tables in the DataSource you wish to included in the dataset.


w. Click the 'Finish...' button.


x. A copy of the Access database you selected and a DataSet are added to the DataService project.



y. Right-click the database and select 'Properties'.


z. The 'Properties' panel will open. In the Properties panel set the 'Copy to Output Directory' property to 'Copy if newer'. This will ensure that changes are reflected in the database as you program and debug your application. If you leave the default setting 'Copy always' a fresh copy of the database will be copied to the Bin directory each time you execute the application and you will not see changes in the database made before the current run.



NOTE: If your application will use more than one Access database, repeat the process of adding a DataSource for each Access database. Additional databases can be added as your application's data needs expand. In the example solution two Access database data sources have been added.





That's it for this installment of the article. In this installment a basic class library (DLL) has been created that can be extended to become a data access layer for Microsoft Access databases. In the next installment the class library will be extended and used for the first time by a Windows Forms application
Anilrgowda is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
   


   
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 10:42 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

DMCA Policy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228