نوشته شده توسط
MAZAHER70
بازم درست نشد
اگه من یه sp داشته باشم و بخوام ارگومان بهش بدم این درسته:proce2 @k,@f output
یا اینکه فقط اسمشو بنویسم بعد پارامتر هامو بهش add کنم اگه اینجوری باشه اونوقت output چطوری add کنم
بله شما باید توی CommandText فقط اسم sp رو بدید مثلا proce2 و بعد آرگومان هاشو بهش add کنید من خودم یه تابع دارم به این شکل
public bool ExecuteNoneQuery(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
using (SqlConnection con = new SqlConnection(ConnectionString))
{
bool execute = false;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
if (commandParameters != null && commandParameters.Length > 0)
cmd.Parameters.AddRange(commandParameters);
con.Open();
try
{
cmd.ExecuteNonQuery();
execute = true;
}
catch (SqlException exception)
{
throw exception;
execute = false;
}
con.Close();
return execute;
}
}
و بعد از این تابع به این صورت استفاده میکنم
public bool Update(int dcID, string vcName, string vcPersonnelID, string vcTel, string vcAddress)
{
return ExecuteNoneQuery(System.Data.CommandType.StoredPro cedure, "sp_UPD_Store", new SqlParameter[]{
new SqlParameter("@dcID",dcID),
new SqlParameter("@vcName",vcName),
new SqlParameter("@vcPersonnelID",vcPersonnelID),
new SqlParameter("@vcTel",vcTel),
new SqlParameter("@vcAddress",vcAddress),
});
}