Tuesday, 4 December 2012

Using Sql Parameter in Connected Mode


Using Sql Parameter in Connected Mode

// Sql Parameter in Connected Mode...

// To use Sql Parameter first of all you have to create a STORE PROCEDURE in Sql ...

 protected void bt1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=deepak-pc;Initial Catalog=mydb;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("getrecordbyid", con);
        cmd.CommandType = CommandType.StoredProcedure;
       
 
     
 
        SqlParameter p1 = new SqlParameter("@id", SqlDbType.Int);
        p1.Value = TextBox1.Text;
      
 
        cmd.Parameters.Add(p1);
      
 
        con.Open();
      SqlDataReader dr=  cmd.ExecuteReader();
      while (dr.Read())
      {
          Response.Write(dr[0]);
      }
        con.Close();

    }
  

No comments:

Post a Comment