ASP.Net with MS SQL Database
In this blog I'll explain how to create database in MSSQL and connect it to ASP.Net web application.
1. Create a database Employee.
11. Add jQuery to script folder and add script.js to add custom scripts
1. Create a database Employee.
Set identity to the ‘id’ column. This will auto increment the id by 1 each time when the record is added.
2. Create a Stored Procedure called ‘AddEmployee’.
Stored Procedures are queries that you can write once and execute multiple times.
Set the required parameters using following format:
@parameter_name parameter_type (size)
Stored Procedures are queries that you can write once and execute multiple times.
Set the required parameters using following format:
@parameter_name parameter_type (size)
3. Create empty ASP.Net project using Visual Studio.
4. Add ConnectionString attribute to the Web.config
file to get connected with our database.
5. Create a dbConnection.cs to get connection
string from the Web.config file.
6. Create Employee class.
NOTE: If you are using AJAX this class might be a problem when the
JSON object names are not matched with this object property names. So decorate
the class properties with the JsonProperty attribute.
7. Crete class called UserManager to interact with
Employee.
8. Create Web Form to interact with Employee. I'll use the default page.
9. Code behind to get the Employee data
10. Code behind to Add Employee
In this section I have explained two methods. If you want to access this method from client side then you must add the [WebMethod] attribute (Explained in b).
In this section I have explained two methods. If you want to access this method from client side then you must add the [WebMethod] attribute (Explained in b).
a.
From the Server side using a button OnClick
event
b.
From Client side using button OnClientClick
event
11. Add jQuery to script folder and add script.js to add custom scripts
12. Add the javascript to save Employee
Comments
Post a Comment