Exercise one: Use a data access program block to execute a static SQL statement
This exercise demonstrates how to use the data access block for the most basic data access, and how to configure the program block to provide runtime and then select the database.
First step
Open the SimpleData.sln project, the default installation path should be C:\Program Files\Microsoft Enterprise Library January 2006\labs\cs\data Exercises\ex01\begin, and compiled.
The second step is to create the QuickStarts database
1. Open Dataaccessquickstarts.sql with Notepad, the default installation path should be C:\Program Files\Microsoft Enterprise Library January Data, select File | Save as a menu and select the encoding format encoding for Unicode, save and overwrite the original file and read-only property, remove the read-only property from the file properties.
2. Under the same directory, run the Setupquickstartsdb.bat batch file, and note that the database will be installed under the default instance (local) \SQLExpress, and if you need to change it, Use Notepad to open the Setupquickstartsdb.bat file for modification.
Third Step Review Application
Select MainForm.cs file in Visual Studio 2005 Solution Manager, select View | Designer menu, the application contains a DataGrid and several menus, and we will use the data Access Application block to count the number of customer in the database and load the data into the DataGrid.
Step fourth to implement the Customer menu item
1. Select the Customermanagment project, select Project | Add Reference ... menu command, select Browse in the Open dialog box, and add the following two assemblies.
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
The default location should be the C:\Program Files\Microsoft Enterprise Library January 2006\bin.