[Solved] ExecuteNonQuery always return -1 in ASP.Net

tanweeruddinbeeharry
 
on Oct 15, 2021 10:56 PM
451 Views

Whenever this function is excuted it always return -1. Even the row is affected. why?

public static String TransactionQuery(String SpName, List<SqlParameter> parameters)
{
    using (SqlConnection con = new SqlConnection(_conString))
    {
        using (SqlCommand cmd = new SqlCommand(SpName))
        {
            cmd.Parameters.AddRange(parameters.ToArray());
            cmd.CommandType = CommandType.StoredProcedure;
 
            cmd.Connection = con;
            con.Open();
            if (cmd.ExecuteNonQuery() > 0)
            {
                con.Close();
                return "SUCCESS";                           
            }
            else
            {
                con.Close();
                return "FAIL";                            
            }
        }
    }
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Oct 15, 2021 11:11 PM

Hi tanweeruddinb...,

Make Sure you have not set SET NOCOUNT ON in stored procedure.

SET NOCOUNT ON is used to suppress the counts of records affected in your stored procedure.