how to use the count command?and how can store the result of count command in a veriable of integer type????
count command in sql
Collapse
X
-
-
sir i want to store the result in a integer type variable
like
Code:<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Web.Configuration" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Private Sub Page_Load() lblMovieCount.Text = GetMovieCount().ToString() End Sub Private Function GetMovieCount() As Integer Dim result As Integer = 0 Dim connectionString As String = WebConfigurationManager.ConnectionStrings ("Movies").ConnectionString Dim con As New SqlConnection(connectionString) Dim cmd As New SqlCommand("GetMovieCount", con) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@ReturnVal", SqlDbType.Int).Direction = ParameterDirection .ReturnValue Using con con.Open() cmd.ExecuteNonQuery() result = CType(cmd.Parameters("@ReturnVal").Value, Integer) End Using Return result End Function </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Show Movie Count</title> </head> <body> <form id="form1" runat="server"> <div> There are <asp:Label id="lblMovieCount" Runat="server" /> movies in the database. </div> </form> </body> </html>
but this code is in VB.what is the code in C# please tell me.Last edited by Frinavale; Sep 15 '10, 02:09 PM. Reason: Please post code in [code] ... [/code] tags. Changed the <code> tags into [code] tags.Comment
-
VB.NET and C# my have different syntax but they both call the same library (the .NET Framework...) to accomplish the same thing.
Please attempt to read through the code above to understand the logic. Once you understand the logic then you should have no problem implementing the same thing in C#.
If you get stuck, ask and I'll help you through whatever you don't understand.
-Frinny
P.S.
The CType function is simply casting the value returned into an Integer.
It's the same thing as this in C#:
Code:result = (Integer)cmd.Parameters("@ReturnVal").Value;Last edited by Frinavale; Sep 15 '10, 02:22 PM.Comment
Comment