Search This Blog

Monday, December 12, 2016

Sql Connection in three different ways

Step1:
Welcome to designers bog

Step1: 

        SqlConnection con = new SqlConnection(@"data source=VAIO\SQLEXPRESS; database=Sample;  integrated security=True");
            SqlCommand cmd = new SqlCommand("Select * from tb1Product", con);
            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            GridView1.DataSource = rdr;
            GridView1.DataBind();
            con.Close();

Step2:




            string cs = @"data source=VAIO\SQLEXPRESS; database=Sample; integrated security=True";
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand("Select * from tb1Product", con);
            con.Open();
            GridView1.DataSource = cmd.ExecuteReader();
            GridView1.DataBind();
            con.Close();

Step3:
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("Select * from tb1Product", con);
                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
            }

Step4:


Connection string using web config file


   <connectionStrings>
      <add name="DBCS" connectionString="data source=VAIO\SQLEXPRESS; database=Sample; integrated security=True"
           providerName="System.Data.SqlClient"   />

</connectionStrings>



 string cs=  ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("Select * from tb1Product", con);
                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
            }


  

Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...