Utilisez try catch. s'il ne fait pas exception, la requête a été exécuté avec succès, puis retourne vrai si sucess, return false si elle nest pas exemple
public static bool InsertObFile(PreApprove p)
{
var command = new SqlCommand();
command.CommandText = "ObInsertPreApprove";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@EmployeeAutoId", p.EmployeeAutoId).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@EmployeeId", p.EmployeeId).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@DateFrom", p.DateFrom).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@DateTo", p.DateTo).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@Description", p.Description).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@CreateUserId", p.CreateUserId).Direction = ParameterDirection.Input;
try
{
SqlHelper.ExecuteNonQuery(command); // this is where I run my stored procedure
return true;
}
catch (Exception e)
{
return false;
}
}
Quelle est votre 'CDataContext()', quel est votre 'MySproc()'. Quoi qu'il en soit, vous pouvez essayer 'executenonquery': https://msdn.microsoft.com/fr-fr/library/system.data.sqlclient.sqlcommand.executenonquery(v=vs.110).aspx – Jacky
S'il n'a pas jeté , il fonctionne avec succès. Peut-être que vous voulez dire autre chose? Ne pas insérer ou ne pas mettre à jour n'est pas un échec. –
N'obtiendrez-vous pas une exception si elle échoue? Donc, si vous n'obtenez pas d'exception, cela doit être réussi ... Je ne fais que spéculer – musefan