اول کانکش رو باز می کنیم یک شی command ایجاد می کنی وCommandText اون رو به نام sp ست می کنی و بعد CommandType اون رو به StoredProcedure ست می کنی و بعد اگه پارامتر داشتی بهcammand اضافه می کنی و در نهایت اجرای کامند بسته به خروجی که می خوای. کافی تو تابعی که ایجاد کردی sp رو به عنوان پارامتر تابع بگیری و خروج تابع رو تنظیم کنی که من اینجا از نوع datareadar گرفتم مثل کد زیر
public IDataReader functionName(string sp)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand(sp, cn);
cmd.CommandType = CommandType.StoredProcedure;
cn.Open();
cmd.Parameters.Add("@parameterName", parameterType).Value = parameterValue;
IDataReader reader = cmd .ExecuteReader;
if (reader.Read())
return reader;
else
return null;
}
}