 <p>You've got a query. Therefore this call is inappropriate:</p> <pre><code>OIMScmd.ExecuteNonQuery(); </code></pre> <p>Instead, you should be using <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx" rel="nofollow"><code>ExecuteScalar()</code></a>:</p> <pre><code>int count = (int) OIMScmd.ExecuteScalar(); </code></pre> <p>(It's possible that it'll return a <code>long</code> rather than an <code>int</code> - I'm not sure offhand.)</p> <p>Additionally, you should use a <code>using</code> statement for the <code>SqlCommand</code> and create a new connection for each operation:</p> <pre><code>using (var connection = new SqlConnection(...)) { connection.Open(); using (var command = new SqlCommand(query, connection)) { int count = (int) command.ExecuteScalar(); // Now use the count } } </code></pre> <p>It's also not clear what kind of app this is - if it's in a local GUI (WinForms or WPF) you should <em>not</em> be performing database access on the UI thread. The UI will be frozen while the database access occurs. (If this is in a web application, it's even more important that you create a new database connection each time... you don't want two separate requests trying to use the same connection at the same time.)</p>