getting value from database into integer


I have an sql statmetn that counts all the votes in the table. i need this to calculate the quota. My problem is how to i get the value(i.e the count of the votes) into the area thats colored red below?

SqlCommand SqlCmd1 = new SqlCommand("SELECT count(vote)FROM PRTest", SqlCon1);

int quota =  (count(Vote) + 1) / ((11) + 1);

Response.Write(quota);

0
dotnetGoat
3/16/2006 5:28:22 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
466 Views

Similar Articles

[PageSpeed] 40

You can use ExecuteScalar method.  Following is an example from the online documentation for SqlCommand.ExecuteScalar method:

static public int AddProductCategory(string newName, string connString)
{
    Int32 newProdID = 0;
    string sql =
      "INSERT INTO Production.ProductCategory (Name) VALUES (@Name); "
        + "SELECT CAST(scope_identity() AS int)";
    using (SqlConnection conn = new SqlConnection(connString))
    {
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.Parameters.Add("@Name", SqlDbType.VarChar);
        cmd.Parameters["@name"].Value = newName;
        try
        {
            conn.Open();
            newProdID = (Int32)cmd.ExecuteScalar();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
    return (int)newProdID;
}
 
0
jcasp
3/16/2006 6:48:05 PM
Reply:

Similar Artilces:

Get a value from SQL Database...
Sorry, this maybe a very easy problem... I just want to know how get a value from SQL database ... since I am new to SQL server... I already have code like this:     Dim queryString As String = "SELECT Password FROM [User] WHERE Name = 'Sprite'"    Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand    dbCommand.CommandText = queryString    dbCommand.Connection = dbConnection What should I do next to get the value ? thx for your help :) Just had a try, and it works~ haha... Here is the code for ot...

How to pass in value to javascript from database or let javascript to get value from database?
I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won't change.Do I need Ajax?Thank you.  hanxiao:I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won&...

Query for substring to get some particular value in a string (Get querystring value by sql )
I have a column name URL in Table1 with data like  <a href="/Folder1/view_media_news.cfm?news_media_i=1">August 2002 Factsheet</a>            <a href="/Folder1/view_media_news.cfm?news_media_i=149">March 2002 Newsletter </a>  i need to grab the news_media_i value by sql query  Please any one can help me to get that particular value from string using substring or any other suggestion Thank you in advance SurendraIf this helps mark it as answer surendra_kla:i nee...

Getting a Single Value from a SQL Server database
Hi:  I am new as .net and am trying to get a single result value back from a database using the statement  "SELECT MAX(id) from databasename"  I have written the following function and put it in a class (along with its required functions) so I can call it at anytime.   Public Function GetValue(ByVal sqlStatement As String) As Integer Dim myCommand As New SqlCommand(sqlStatement, oDBConn) myCommand.Connection.Open() Dim value As Integer = CType(myCommand.ExecuteScalar(), Integer) oDBConn.Close() Return value   End Function   When I use cod...

c#
I am a nebbie to .net! I am changing an application which reads an sql database - (does a param search) . I need to be able to output a message to screen when no records exist for search. Application is using a Repeater which reads - data table to output records to the application. The query to the database is in a different class. Can get message to output on screen when I force, so I know the syntax is working.  I just need to know how I can get at return (bool - true/false) so I can test on this. Can anyone out there help? Don't worry, this is not a newbie issue.. Many of...

how to get just a single value from an sql database and show it in a table.
I would like to get single values from a huge sql server and put it into a table. let's say 4 by 4. How do I do that? I have a connection string with a select statement that will only return a value. But, I do not know how to put that value into a table. Thank you. Hi,You want to display data from a SQL Server database on a page having a 4 x 4 Table right? Trying reading a bit about using GridView Control, or give me a bit more detailRegards,Muhammad Khurram Punjwani Dear mic_lch If you only want to display value. I think gridview is the best solution. Can u give me mo...

Getting a value set to Null.NullInteger to be set as Null on an SQL database
I am using the CodeSmith DNN templates and finding them great for coding.  When I set a feild in an Info class to Null.NullInteger then pass this to a controller to update, the SQL parameter value that is passed is -1 rather than Null.What's the best way to correct this?Jonathan Palmer Any news on this? I'm having the exact same problem.Juliana -1 is null for an integer. Are you wrapping the sproc argument with GetNull() in your SqlDataProvider? Best Regards, Jason The issues is when you have an integer value that can be minus - e.g. temperature in degrees and you a...

How to get comma seperated value from sql 2000 database using store procedure
Hi I have two table in database. I m using sql 2000 database..one is user and another is useraccess level table..Useraccess table i m storing userid and accesslever. User Table userid username userfirstname.......1        abc           steve2        xyz           paula3        pqr           Haian   Useraccess Table Userid &n...

How to get comma seperated value from sql 2000 database using store procedure
How to get comma seperated value from sql 2000 database using store procedure  Hi I have two table in database. I m using sql 2000 database..one is user and another is useraccess level table..Useraccess table i m storing userid and accesslever. User Table userid username userfirstname.......1        abc           steve2        xyz           paula3        pqr    ...

Getting lowest integer value in an array of integers
Hi, the subject pretty much says it all. Is there a function in vb.net that runs through an array of integers and grabs the lowest number? Thanks in advance. you can use Array.Sort() and then just access the first integer (although it may put the smallest integer in arr[0] not arr[1]) or you can write your own int i = arr[0]; for (int j=0; j<arr.Length;j++) if(arr[j]<i) i=j; I'm not sure how that translates to VB if you need to start from 1 or 0 thanks bsaperst, will give that a go....

DropDown List DataSource for Options *AND* for DataSource Value in Database?
  I have a DropDown object list and so far I can set it to EITHER: 1) A SINGLE value (From table A using DataSource1)2) Multiple value options (From table B using DataSource2)  But how do I set both of the above? (i.e. set it to the value of option DataSource1 but allow the user to set it to any value in DataSource2)  Thanks ! wht do u mean?? binding dropdown to one datasource containg ds1 and ds2??Please remember to "Mark As Answer" if this post answered your question!Bilal Shouman - MCAD.NET|My Blog|--------------------------------- you can only bind...

Can connect to Database, but how do I insert values into SQL Database?
I was able to connect to the SQL Database Pension with table clients with table values: ID, State, Name.'Create(connection)Dim conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)'open connectionconn.Open()However, I'm not sure how to insert a new row with an incremental ID number and a new State and Name.Sorry, I'm really new with VWD. You need to read about ADO.NET before you do anything. Google it.ASP.NET Hosting (HostingFest)...

Getting a SQL Database Error...any ideas SQL experts?
 I am trying to insert a value into a field in a database named ASPNETDB.MDF.  The table name is "profiles_BasicProperties" and the field name is "UserID".  I get an error when I attempt to do this.  See the code I am using to try to do this below...and then the error that I get which is further down in this post.  Note...both the code and the database are on my laptop.  I can connect to the database just fine using Server Explorer in MS VS 2005.  Thanks in advance for any help anybody can offer...  Here is the code I am using: &l...

Getting a SQL Express Database to work on a SQL Server
Hi, I'm getting ready to deploy an ASP.NET application to a server that does not support SQL Express, but does support MS Access and SQL Server. Is there any easy way to convert my SQL Express code to either Access or regular SQL Server code, without having to change very much code in my application. I really like the integration that SQL Express has with Visual Web Developer, and would like to be able to keep that sort of integration if at all possible. Thanks,Drew Assuming by "SQL Server" you mean "SQL Server 2005", the only thing that should need to change is the connection string.&n...

Web resources about - getting value from database into integer - asp.net.sql-datasource

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

Dodgy database exposes details of 191 million US voters
... years, there's a high chance that your personal details are now out in the wild. Security researcher Chris Vickery found a misconfigured database ...

Huge database of 191 million U.S. voters found on the open Internet
... such bulk information online, a recent discovery seems to indicate. According to VentureBeat , a security researcher found the exposed database ...

3.3 million Hello Kitty fans' details have been exposed in a huge database leak
... week after week, the hacks, breaches and data leaks continue to roll in. The latest victim? Hello Kitty. CSO Online is reporting that a database ...

Massive Voter Database Left Open For Public Consumption
Gosh, we could have avoided all the angst about the Clinton/Sanders voter database breach if only we'd known about this major database , accessible ...

Database configuration issues expose 191 million voter records
A misconfigured database has led to the disclosure of 191 million voter records. The database, discovered by researcher Chris Vickery, doesn't ...

Botched database leaks records for 191 million voters
... sometime this century? If so, your personal info may be out in the open. Researcher Chris Vickery has discovered that a badly configured database ...

191 Million US Voter Registration Records Leaked In Mystery Database
A huge database of 191 million US citizens is uncovered. But no one knows who carelessly left it open, whilst the FBI have been contacted.

Database Leak Exposes 3.3 Million 'Hello Kitty' Fans
... was accessible. Vickery told Reuters by e-mail that the company had plugged the holes he had found in three servers. But he said the database ...

Resources last updated: 1/9/2016 7:15:17 PM