how to connect SQL Database in Using C#

in this tutorial we will learn how to connect SQL Database in Using C# with help of Visual Studio so guyies let's get's started to crerate connection of SQL Database.

how to connect SQL Database in Using C#

First Step:

You need to left click of mouse in Solution Explolar which give left corner of Visual Studio. If you have not got this then you need to goes View Menu  and choose solution explolar. That’s fine.

Second Step:

You need to right click of mouse on Data Connection and choose Add Connection then you got a popup box.

Third Step:

Here we will copy or find Server Name from SQL Express Popup Box and paste in Visual Studio popup where given Server Name and choose your Database which given in image select or enter a database name and left click of mouse on Text Connection if you got Successfully message then Database Connected Successfully.

Fourth Step:

Now you need to find Connection string of database so you need to click on Advanced Button and copy all connection string text paste in your Sql connection string which given following code

using System.Data;
using System.Data.SqlClient;

 private void btnreg_Click(object sender, EventArgs e)
            SqlConnection con =new SqlConnection("Data Source=WINCTRL-NAA1ARS\\SQLEXPRESS;Initial Catalog=dbdemo;Integrated Security=True");