Windows Application Connectivity with SQL-Server using Wizard in ASP.Net C#

Here, In this asp.net tutorials we will learn to make connection between SQL-Server and Windows Application in ASP.Net.

We can use many server for connectivity, here we will learn sql server database connection in asp.net. ms sql server is most popular database server.There are  many names of SQL-Server like mssql server, ms sql server, sql server client, database server, mssql server…..

We can do this connectivity with multiple methods.

Connection between Windows Application and SQL-Server using Wizard (TableAdapter Method)

Connection between Windows Application and SQL-Server using DataAdapter and SQLConnection Method

Before, going to ahead we need to create DataBase in SQL-Server,

Here, some step to create new sql-server Database in SQL-Management Studio.

STEP 1 – Open SQL-Server Management Studion and Create a New Database..

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

After opening SQL Server Create New DataBase

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Write your New Database Name which you want to create in SQL-Server….and Click OK Button to Create New DataBase.

Connectivity Between Windows Application SQL-ServerConnectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Now Create New Table in Database..

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

 Create Column in your Table and Save Table with UserMst name.

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

After Creating Database and Table in SQL-Server, open the Visual Studio and Create New Windows Application in ASP.Net.

Open Visual Studio —> File –>  New —> Project

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Here, Select the Windows Form Application and write your Project Name, We create project named DEMO Here.

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

After Creating project you have a one Windows Form…..

Now, Here we create connection using Wizard so, Create New Folder at Solution Explorer and Create New DataSet in that DS Folder.

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Open the DataSet1 and create New TableAdapter by Right clicking on DataSet1.

Then give your server name for new connection, just select your Database like below screen…

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Then Click Next button and Select Use Existing Stored Procedure option on below screen.

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Select the Stored Procedure for Select and Insert which are already you created in sql server.

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

Now,  Remove the Fill a DataTable option and Next….

Connectivity Between Windows Application SQL-Server
Connectivity Between Windows Application SQL-Server

After Finishing this connectivity wizard, open your windows form and design like below:

Here, we have two TextBox Control Named txtname,txtcity and one Insert Button and one GridView Control.

wwwindows7

Write Below code on INSERT Button Click Event:

private void btninsert_Click(object sender, EventArgs e)
{
DS.DataSet1.USERMST_SELECTDataTable UDT = new DEMO.DS.DataSet1.USERMST_SELECTDataTable();
DS.DataSet1TableAdapters.USERMST_SELECTTableAdapter UAdapter = new DEMO.DS.DataSet1TableAdapters.USERMST_SELECTTableAdapter();

int inst = UAdapter.Insert(txtname.Text, txtcity.Text);
txtname.Text = “”;
txtcity.Text = “”;

UDT = UAdapter.SelectData();
GvData.DataSource = UDT;
}

I hope you will enjoy this asp.net tutorials of  sql server database connection in asp.net, database connection in vb.net with sql server.

Leave a Reply

Your email address will not be published. Required fields are marked *