Social Club: Sample application using Win. Forms, C#. NET, ADO. NET and MS Access. Contents. Introduction. This article discusses about a simple windows database application developed using C#. It uses Win. Forms on the front- end (UI) and MS access as back- end (DB). The application is named “Social Club”, as it is to create and manage club member’s information. The application User interface (UI) comprises of few screens (Login, Registration, Manage). Registration screen is to create/register new club membership. Mange screen provides options to Edit, Delete, Search, Print club members information & export data to excel. This article will focus on demonstrating how some topics are applied in the sample demo project; topics like 3- Tier architecture, Connection to access database, Creating basic SQL statements for access database, Writing ADO. NET code, Implementing CURD operation using Win. Forms and C#. NET. Software environment. Application is developed in the following software environment. Development environment : Visual Studio. NET 2. 01. 0 Framework : . NET Framework 4. 0 User Interface : Windows Forms Programming language : C#. NET Data Access : ADO. NET Database : MS Access 2. Code analysis tool : Stylecop Pre- Requisite. You need to have the following tools installed in your machine to run the sample application. Microsoft Visual Studio 2. Microsoft Access 2. Layered architecture. Free Access Database Sample, Employee Expenses Database. Let us package your database with Microsoft. You pay only for the time required to develop and package your database using the runtime. Northwind Sample Database. This article analyzes the Northwind sample database first offered with Microsoft SQL Server 2000. Eastman’s TLC Total Lifecycle Care. This comprehensive program includes system design support, start up.Presentation Layer. Presentation (Desktop) Layer is the topmost layer contains the User Interface of the application. This layer is responsible for delivery of information to the user and to the application.
It contains Forms (UI) for user interaction and code- behind (UI Logic) to handle the events. Data Layer. Data layer is the middle- layer and it contains the business service methods, data access logic, data model and SQL scripts. Business service. Business service contains method to communicate with the data access. It acts as a bridge between Presentation logic and data access logic. This layer is responsible for calling the data access methods and delivering the result to presentation. Data Model. The data model contains properties that reflect the data; this is often called entity/business objects. SQL Scripts. SQL Scripts contains SQL statements that carry the database logic. Data access. Data access typically contains the logic for accessing the database data and is generally implemented in a separate class library project. In the demo project Business Service and Data Access are implemented in the same class library. Database Layer. Database layer contains Database with table structure & data. Project Structure. Solution explorer shows how the directories are structured within the projects. Solution contains two projects. Desktop (Windows Project)Desktop project which is a Windows Forms Application project that contains Forms (UI) and corresponding code- behind (. Controlled Substance Monitoring Database Program Frequently Asked Questions. The Tennessee Prescription Safety Act of 2016, Tenn. 1002 represents a significant effort by the General Assembly to address the. CS) files. Code- behind files contains the UI logic to handle the events. Data (Library Project)Data project is a Class library project that contains the database logic (SQL scripts), data access logic (ADO. NET code), and data model (Business entity). All service methods and data related logic resides in the same class library. Preferably, each of these will be in separate class library project in a multi- tier architecture system and the library projects will be referenced in whichever project it is necessary. Organizing the folders, files, projects in this fashion separates the code into distinct sections such that each section addresses a separate concern. This is a design principle for separating the program into sections. This make the code reusable, readable, flexible to manage and maintain. Creating the database. Social club application requires only a single table to store the club member information. Below displayed image shows the database in the design view. It show the table on the left panel and details (Field Name, Data Type, Description) on the right panel. For each Field Properties can be set through the . Right click on the table and go to the design view (A small window will prompt to save the table) Give the name to the table (in our case, the table name is “Club. Member”) and click save. Create the fields (columns) with necessary data type, properties and description. Click the “Save database as” option in the “File” menu and save the database by giving an appropriate name (In our case, the database name is “Social. Club”). Database is saved as . Setting up the project. I presume that you are aware of the visual studio environment to some extent. Here I’ll list down the steps to set up the Desktop and Data project. Open visual studio and Select File - > New - > Project In the new project window, Select “Visual studio solution” from “Other project types” templates Give the project name as “Social. Club” and click OK. Right click the solution and select Add - > New project In the new project window, From the templates Select Visual C# - > Windows - > Windows Forms Application Give the project name “Social. Club. Desktop” and click OK Again, Right click the solution and select Add - > New project In the new project window, From the templates Select Visual C# - > Windows - > Class Library Give the project name “Social. Club. Data” and click OK In the “Social. Club. Desktop” project, right click on References and Select Add reference From the Add Reference window, Select “Projects” tab - > Social. Club. Data Project and Click OK Press CTRL+SHFT+B and check if the application builds. Copy the database file (Social. Club. accdb) to the bin directory located in the application startup path Now, you have setup the project in visual studio and ready to go with the coding. Below shown is the visual studio screen shot for Step 1. Implementing the Data Layer. Named constants (Enums)A set of named constants (enum) is created for the fields (Health status, Marital Status, Occupation). These fields in the database will contain the numeric equivalent of enum value and these fields in the data model will be of respective enum type. Also these enumerated values (string equivalent) are shown in dropdown list in the UI for selection. Class Diagram. Sample codepublicenum Health. Status. . This entity will be used as data transfer object (DTO) simply to transfer the data between the layers. Below shown is the data model created for the sample application. Class Diagram. Codepublicclass Club. Member. Model. . The ACE OLDB 1. Access database. This connection string is passed into data access code for the ADO. NET objects to initiate a connection with the database. Storing the connection string. Generally, Database connection strings are stored in CONFIG file for ease of configuration and are accessed from there. To store the connection string in Configuration file, follow the steps. Right click on the “Social. Club. Desktop” project, Select Add - > New item From “Add New Item” window, Select Visual C# items - > General - > Application configuration file and click OK (app. In the app. config, add the following code < configuration> < connection. Strings> < addname=. The connection string from the app. Configuration. Manager. In the demo project, this done by creating a abstract class called Connection. Access that contains a property called Connection. String Which returns the connection string stored in the config file. This code is shown below: using System. Configuration. publicabstractclass Connection. Access. . It contains set of classes that provides data access service to . NET application. I will take you through some basics of ADO. NET objects used for database communication and steps to load and modify the data. ADO. NET objects. Connection Object. The Connection object is to create a connection between the application and database. Command Object. The Command object is used to store the SQL statements that need to be executed against the database. Command object can execute SELECT, INSERT, UPDATE, DELETE, Stored Procedures. Data. Reader Object. The Data. Reader object is to retrieve data from the database. The Data. Reader object is forward- only read- only type of cursor that provides faster way of retrieving records from the database. Data. Adapter Object. The Data. Adapter object is to retrieve data from the database and populate the data in a Data. Table or Data. Set. Data. Set is an in- memory representation of a database contains Data. Table collection. Data. Adapter object uses the Fill method to populate the data in Data. Set. It uses the connection object and command object to automatically open the connection, execute the command and close the connection. Steps to Load the data using Data. Adapter. Create an instance of Data. Adapter object Assign a new instance of Command Object to Data. Adapter Select. Command property Set the connection and Command property of Select. Command. Add (if any) parameters to the Parameter. Collection of the Select. Command Invoke the Fill method of the Data. Adapter object and pass to it the Data. Table object. Using these ADO. NET objects is relative to the data sources. MS Access is an OLE DB datasource. When connecting to OLEDB datasource, we need to use the Ole. Db. Connection and Ole. Dd. Command in the System. Data. Ole. Db namespace. Sample code. Ole. Db. Data. Adapter ole. Db. Data. Adapter = new Ole. Db. Data. Adapter(). Db. Data. Adapter. Select. Command = new Ole. Db. Command(). ole. Db. Data. Adapter. Select. Command. Connection = new Ole. Db. Connection(this. Connection. String). Db. Data. Adapter. Select. Command. Command. Type = Command. Type. Text. ole. Db. Data. Adapter. Select. Command. Command. Text = Scripts. Sql. Get. All. Club. Members. ole. Db. Data. Adapter. Fill(data. Table); Steps to modify the data using Command object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |