title: output clause returns value but executescalar returns null in c#
body: <p><br>
   I need to get the updated row's first column value. However when I run query <code>Update ClaimDetails set sStatus='False' OUTPUT inserted.slno as Slno where inVoiceNo='******' and sStatus='True'</code>
  <br> in Management Studio it returns the right value. But when I try to get the value using <code>Executescalar()</code> it returns null</p>
  
  <p>My code:</p>
  
  <pre><code> bool isupdated = false;
          int modified=0;
          try
          {
  
              string updateqry = "Update ClaimDetails set sStatus=@sStatus OUTPUT inserted.slno as Slno where inVoiceNo=@inVoiceNo and sStatus='True'";
              SqlCommand cmd = new SqlCommand(updateqry, con);
              cmd.Parameters.AddWithValue("@sStatus", sStatus);
              cmd.Parameters.AddWithValue("@inVoiceNo", inVoiceNo);
              connect();
              if (cmd.ExecuteNonQuery() &gt; 0)
              {
                  isupdated = true;
                   //modified = (int)cmd.ExecuteScalar();
                  object a = cmd.ExecuteScalar();
                  if (a != null)
                      modified = Convert.ToInt32(a);
  
              }
          }
          catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
          finally { disconnect(); }
          return modified;
  </code></pre>
  
  <p>When I used <code>modified = (int)cmd.ExecuteScalar();</code> it gave me an exception error so I used <code>object</code></p>