ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.Display number of Records in Label using C# in ASP.Net<blockquote><cite>AnkitPal says:</cite> <div class="line number2 index1 alt1"><code class="csharp plain">SqlCommand cmd = </code><code class="csharp keyword">new</code> <code class="csharp plain">SqlCommand(</code><code class="csharp string">"SELECT COUNT(*) column_name FROM table_name"</code><code class="csharp plain">, cnn);</code></div> <div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">cnn.Open();</code></div> <div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">SqlDataReader rdr = cmd.ExecuteReader();</code></div> <div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">int</code> <code class="csharp plain">count = 0;</code></div> <div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(rdr.Read())</code></div> <div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">count++;</code></div> <div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">label1.Text = </code><code class="csharp string">"("</code> <code class="csharp plain">+count.ToString() + </code><code class="csharp string">") "</code> <code class="csharp plain">+ </code><code class="csharp string">"records"</code><code class="csharp plain">;</code></div> <div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">cnn.Close();</code></div> <div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> </blockquote> <p>&nbsp;replace above code with below</p> <pre class="brush: csharp">SqlCommand cmd = new SqlCommand(&#34;SELECT COUNT(*) Total_Count FROM table_name&#34;, cnn); { cnn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { label1.Text = &#34;(&#34; + rdr[&#34;Total_Count&#34;].ToString() + &#34;) &#34; + &#34;records&#34;; } cnn.Close(); }</pre> <p>&nbsp;</p>http://www.aspforums.net/Threads/195979/Display-number-of-Records-in-Label-using-C-in-ASPNet/http://www.aspforums.net/Threads/195979/Display-number-of-Records-in-Label-using-C-in-ASPNet/Mon, 09 Jan 2017 03:18:18 GMTDisplay number of Records in Label using C# in ASP.Net<p>Thanks Buddy,</p> <p>It was perfect answer.</p>http://www.aspforums.net/Threads/195979/Display-number-of-Records-in-Label-using-C-in-ASPNet/http://www.aspforums.net/Threads/195979/Display-number-of-Records-in-Label-using-C-in-ASPNet/Mon, 09 Jan 2017 03:23:32 GMT