Saturday, March 13, 2021

How To Connect SQL Database In ASP.NET Using C# And Insert And View The Data Using Visual Studio 2015

How To Connect SQL Database In ASP.NET Using C# And Insert And View The Data Using Visual Studio 2015




Introduction
This article explains how to connect the SQL database into ASP.net using C# language and how to insert and view the data, using Visual Studio 2015 Update 3.

Requirements
Visual Studio 2015 Update 3ASP.NET 4.5.2SQL Server
If you want to connect to the SQL database into ASP.NET, using C#, it should follow the steps given below.
Step 1
Now, Open Visual Studio 2015 Update 3, go to the File >> New >> Project or use the shortcut key "Ctrl+Shift +N".
Step 2
Here, select Visual C# >> Web >> ASP.NET Web Application. Finally, click "OK" button.
Step 3
Here, you can select the template for your ASP.NET Application. We are choosing "Empty" here. Now, click OK button.
Step 4
Now, open the project and look for the Solution Explorer.  Here, open the default .aspx. If you want a Webform, you can add the page (Web Form). Add+New item (Ctrl+Shift+A). Now, we can create a login page, using ASP.NET code. You need to follow the drag and drop method. Here, we already created the login page.
Step 5      
Now, open the project. If you want a SQL Server database, you can add the page (SQL Server database). Add+New item (Ctrl+Shift+A).Here, you can select Visual C# and choose SQL Server database. Afterwards, click "OK" button.
 Here, open the new Window and click YES button. 
 Now, add this to the database in our project.
 Step 6
Now, we can go to the Server Explorer and add your database. You can click the Tables and afterwards, click Add New Table.
 Now, open the new table and you can fill the data, which is like (studentname, password) and afterwards, you click the Update .
 Here, click database in update and subsequently click update the database.
 Here, the database is updated.
Here, the database and data are added.
Now, we can click  on the right click and click Show Table Data. 
 Now, the data is stored. 
 Step 7 
Now, you can add SQL Data Source. Drag and drop method. Here, click Configure Data Source
 Now, we can choose your database and click NEXT button. 
Now, you can select the ConnectionString and Click NEXT button
Now, we can choose Specify columns from a table or view and afterwards, click Next button.
Now, click Test Query.
Here, add the data and click Finish button.
 Step 8Now, you can go to CS(C# code) page and you will write the C# code. 

https://www.c-sharpcorner.com/article/how-to-connect-sql-database-in-asp-net-using-c-sharp-and-insert-and-view-the-data-usi/



No comments:

Post a Comment