Jesoba.com is launched, Click below image to access it

Jesoba.com is launched, Click below image to access it
Technology and Entertainment Blog

How to create SQL Connection and execute Select query using C#.Net.

Ttitle : How to create SQL Connection and execute Select query using C#.Net.

Article ID : ADO0001

Description : This code will help you to understand how to connect sql connection to .Net framework
using ADO.Net Data Access Technology.


Use below code in your project for SQL Connection

Source Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default : System.Web.UI.Page
{
    string str,str1;
    SqlConnection con ;
    protected void Page_Load(object sender, EventArgs e)
    {
     
         str = "Data Source=[Server Name]; Initial Catalog=[Database Name]; User ID = sa; Password = 12345";  
    }
    protected void OboutButton1_Click2(object sender, EventArgs e)
    {
        con = new SqlConnection(con);
        con.Open();
        str1 = "Select * From emptable where IdEmp = '" + TextBox1.Text + "';
        SqlCommand cmd = new SqlCommand(str1, con);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
            {
                //your code for execution
            }
    }
}


Image/Video : N/A

Keyword : SQL Server Connection, Execute Select Query, .Net.

Reference : N/A

No comments:

Google+ Badge

About Author

My photo

I am Senior Server Expert and Professional Blogger.