Tuesday, 4 December 2012

Using Sql Parameter in DisConnected Mode


Using Sql Parameter in DisConnected Mode

// Sql Parameter in DisConnected Mode...

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


  protected void Button1_Click(object sender, EventArgs e)
    {            
 
                   
 
       SqlConnection connection = new SqlConnection("Data Source=deepak-pc;Initial Catalog=mydb;Integrated Security=True");
     
 
       SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "getrecordbyid";
        SqlParameter p1 = new SqlParameter("@id",SqlDbType.Int);
        p1.Direction = ParameterDirection.Input;
        p1.Value = TextBox1.Text;
        command.Parameters.Add(p1);
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        DataTable dt = new DataTable();
        adapter.Fill(dt);             
 
       
 
    }

No comments:

Post a Comment