Best Cloud Hosting ASP.NET :: Insert Data Into Database by Stored Procedure in ASP.NET C#

BestCloudHostingASP.NET | Best and affordable ASP.NET Hosting. This article shows how to insert data into a database using ASP.Net C# and a Stored Procedure. I used several textboxes and a button. When the user clicks on the “Insert” button the data is saved into the database.


Step 1

Open your Visual Studio 2010 and create an Empty Website, provide a suitable name (insert_demo).

Step 2

In Solution Explorer you get your empty website, then add a Web Form and SQL Server Database as in the following.

For Web Form:

insert_demo (Your Empty Website) then right-click then select Add New Item -> Web Form. Name it insertdata_demo.aspx.

For SQL Server Database:

insert_demo (Your Empty Website) then right-click then select Add New Item -> SQL Server Database. (Add the database inside the App_Data_folder.)


Step 3

In Server Explorer, click on your database (Database.mdf) then select Tables -> Add New Table. Make the table like this:

Table -> tbl_data (Don’t Forget to make ID as IS Identity — True)

Make one Stored Procedure for inserting data into the database, by going to database.mdf then seelct Store Procedures then right-click then select Add New Store Procedure.



Figure 2: Sp Insert


Step 4

Now make some design for your application by going to insertdata_demo.aspx and try the code like this.


Your design will look like this:



Step 5

Now it’s time for server-side coding so that our application works. Open your insertdata_demo.aspx.cs file and code it as in the following.


I hope you like it, thank you for the reading. Have a good Day.

Rate this post