Article Author : Tauseef Ahmad, Article Posted on : 8/2/2017 , Article Category : Asp.net
Here i have explained with an example and attached code that how to save (insert) data in database using asp.net c#.
i am explaining with very easy step by step process with screenshots and code provided.
Step 1. Open SQL Server and Create Database with Table (student).
i created database with name TestDemoDB.
now create table with name student. To make ID filed primary key convert (Is Identity) to yes in column property as mention in screenshot.
Step 2. Now open visual studio ( i used vs 2013 ) and create new empty website just see the screenshot.
now give name to website and click OK.
Step 3. now copy and add the following code in web.config file.
in connectionstring give your datasource name as i gave my own and you give your datasource name and also in database give your database name.
in case your sql server need sql authentication (userid and password ) than just use the following code other wise in window authentication use above code.
Now add new file (aspx)
give name to page.
Add the following code to aspx page this code is used for front end where user enter data.
now open the code behind page and use this code at the top (in namespace).
here is the main code on submit button click.
Use the ConnectionStrings property of the ConfigurationManager class to retrieve the connection string value from web.config.
Command statement for sql query.
when completting all the process save and Run the page give value in the field and check in database table.
insert data, save data, database, ado.net, asp.net, sql command, query,connectionstnig