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.

INITIAL CHAMBER

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.)

DATABASE CHAMBER

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.

Sp_insert

111

Figure 2: Sp Insert

DESIGN CHAMBER

Step 4

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

insertdata_demo.aspx

Your design will look like this:

d

CODE CHAMBER

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.

insertdata_demo.aspx.cs

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

Rate this post