Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

ExecutenonQuery non funziona

innanzitutto, quando si esegue una procedura con parametro(s ), separa i parametri con una virgola

EXECUTE pr_Update @UserID, @Nominated

secondo, modifica il tuo codice in questo,

    string sConnString = System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"].ConnectionString;
    using(SqlConnection mySqlCon = new SqlConnection(sConnString))
    {
        using(SqlCommand mySqlCom = new SqlCommand())
        {
            mySqlCom.Connection = mySqlCon;
            mySqlCom.CommandText = "pr_Update";
            mySqlCom.CommandType = CommandType.StoredProcedure;
            mySqlCom.Parameters.Add("@UserID", SqlDbType.VarChar, 20).Value = UserID;
            mySqlCom.Parameters.Add("@Nominated", SqlDbType.Bit).Value = Nominated;
            try
            {
                mySqlCon.Open();
                mySqlCom.ExecuteNonQuery();
            }
            catch(SqlException ex)
            {
                // do something with the exception
                // don't hide it
            }

        }
    }