So first of all i will show you how to connect database to stand alone application. ( not web application). here are some steps to consider when you designing the application. You must have a proper interface to the application.
The basic steps to designing an interface as follows.
- Operations on DataGridView
- Data Grid View
- Using Meaningful names to user Controllers
After design the interface , now you have to get the database connection. Before connect the database you must create some tables and insert some records. (Ex:- a bank system - you may have more tables like Bank, Branch , Accounts, Account Type etc.) . Then only you can create interface or application to insert data, delete data, update data and so on.
When we come again to connecting the database ( assume we already have create tables on MS SQL Server with records.) there are some steps to follows.
- Importing App.config file - You can create new file called App.config
- Implementing Connection String Inside the file.- how to implement the C.S ??
- Creating new class Connection Manager - what is this Class used for ??
- Importing references System.Configuration - What is this references??
- Create new SQL connection. - how to create new sql connection.??
First of all you must create App.config file ,
Right click on project name in solution explore , Add , New Item
Then select Application Configuration file and clicl Add.
Open the App.config file. The Database connection string can be mentioned here.
To access database objects through our program we need to have a connection to the database from the program. In order to do this a new class called ConfigurationManager will be created. The purpose of having a separate class for this is to develop the project in a structured manner, which will help avoid having to develop the same code in multiple places of the program.
Right click on project name in solution explore , Add , New Item , Class
To use SQL connection in .Net, it is required to import some Reference classes.
To do this, right click on the project file Add Reference…
Right click on project name in solution explore , Add Reference
Also some namespaces needs to be imported in this class.
1. Implement ConnectionManager class.
A sql connection will be created in ConnectionManager class, and a connection created in GetConnection method will be returned
Implement DBAccess class.
Class constructor is modified, in a way that a database connection will be created when an object of DBAcess class is created in the Form.Notice that GetConnection method is used here, which is a static method to establish the connection.
In this class methods will be implemented to access database and return them to the form.
To obtain data from the database through DBAccess class, it is required to create an object of DBAccess class, in the Form class.