Creating, reading, updating, and deleting data tables using code
In this demonstration, we are going to create the sample application. For this, we are going to create a new console application in Visual Studio 2019. We will first connect to our Azure SQL Database account.
Connecting to the Azure SQL database
Follow these steps to connect to establish the connection:
- Open Visual Studio and create a new console app (.NET) project.
- Name the project
PacktSQLApp
. - Right-click on your project in Solution Explorer and select Manage NuGet Packages.
- Select Browse, search for
System.Data.SqlClient
, and install the package. - Open
Program.cs
and replace the references with the following:using System; using System.Data.SqlClient;
- Add the following variable to the
Program.cs
method:static string connectionstring;
- Now, go back to the Azure portal. Navigate to the Azure SQL database that we created in the previous section. Under Settings, select Connection strings...