Thursday, March 12, 2009

Run Stored Procedure In Asp.net With Parameters

SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=server;initial catalog=abc;uid=abc;pwd=abc;";
cn.Open();

SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[dbo].[sp_Fetch_Context_Sensitive_Help]";
SqlParameter para1 = new SqlParameter("@Para1",SqlDbType.VarChar,500);
para1.Direction = ParameterDirection.Input;
para1.Value="1000";
SqlParameter para2 = new SqlParameter("@Para2",SqlDbType.VarChar ,-1 ); // for varchar(max)

para2.Direction = ParameterDirection.Output;


cmd.Parameters.Add(para1);
cmd.Parameters.Add(para2);



SqlDataAdapter adp = new SqlDataAdapter(cmd);


DataSet ds = new DataSet();
adp.Fill(ds);

No comments: