473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

count command in sql

how to use the count command?and how can store the result of count command in a veriable of integer type????
Sep 14 '10 #1
4 2393
Frinavale
9,735 Expert Mod 8TB
Please check out this overview of how to use the Sql Count Function.

-Frinny
Sep 14 '10 #2
sir i want to store the result in a integer type variable
like



Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" %>
  2. <%@ Import Namespace="System.Data" %>
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4. <%@ Import Namespace="System.Web.Configuration" %>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  6.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <script runat="server">
  8.  
  9.     Private Sub Page_Load()
  10.         lblMovieCount.Text = GetMovieCount().ToString()
  11.     End Sub
  12.  
  13.     Private Function GetMovieCount() As Integer
  14.         Dim result As Integer = 0
  15.         Dim connectionString As String = WebConfigurationManager.ConnectionStrings
  16. ("Movies").ConnectionString
  17.         Dim con As New SqlConnection(connectionString)
  18.         Dim cmd As New SqlCommand("GetMovieCount", con)
  19.         cmd.CommandType = CommandType.StoredProcedure
  20.         cmd.Parameters.Add("@ReturnVal", SqlDbType.Int).Direction = ParameterDirection
  21. .ReturnValue
  22.         Using con
  23.             con.Open()
  24.             cmd.ExecuteNonQuery()
  25.             result = CType(cmd.Parameters("@ReturnVal").Value, Integer)
  26.         End Using
  27.         Return result
  28.     End Function
  29. </script>
  30. <html xmlns="http://www.w3.org/1999/xhtml" >
  31. <head id="Head1" runat="server">
  32.     <title>Show Movie Count</title>
  33. </head>
  34. <body>
  35.     <form id="form1" runat="server">
  36.     <div>
  37.  
  38.     There are
  39.     <asp:Label
  40.         id="lblMovieCount"
  41.         Runat="server" />
  42.     movies in the database.
  43.  
  44.     </div>
  45.     </form>
  46. </body>
  47. </html>
  48.  
  49.  

but this code is in VB.what is the code in C# please tell me.
Sep 15 '10 #3
Frinavale
9,735 Expert Mod 8TB
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#:
Expand|Select|Wrap|Line Numbers
  1. result = (Integer)cmd.Parameters("@ReturnVal").Value; 
Sep 15 '10 #4
thanku so much sir..
actually i had problem in this"(result = (Integer)cmd.Parameters("@ReturnVal").Value;)" line which u sortout..
Sep 16 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brendonlam | last post by:
Hi there, Hoping someone could advise me here pls; I'm creating a C# class that implements a telnet client socket allowing a VB . NET application to communicate with telnet servers. After...
2
by: Dr. Laurence Leff | last post by:
How does not compile a Windows API and a Windows MFC program from the command line with Visual.net. (I can do the former, at least, with Visual Studio by creating a "Win32 Project.") However, I...
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
2
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
17
by: News | last post by:
Hi everyone, My goal is to pull command switches/options from a file and then assign the values to select variables which would eventually be included in a class object. The data file looks...
2
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
13
by: Bart | last post by:
Hi, i get the error: "There is already an open DataReader associated with this Command which must be closed first" Thanks Bart ----------------------------------------- Imports...
1
by: gdarian216 | last post by:
okay I had a code that asked user to input a file name and instead i changed it to take the input from the command line. I now want to output results of some functions to an output file. I have...
3
by: deeas | last post by:
hi please how i can read the result of : select count(*) command "SELECT count(*) as FROM devices"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.