SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Row count returns an error

    Hi

    I have a table in a database that I can query using asp.net page and return all results successfully, but I also want to return the row count of a specific column and simply display the total number of rows on an Asp.net page so I can calculate percentage of certain repeated words under this column

    I have included an extract from the code. When I add the count bit, an indexoutbound error is displayed. note without the count, everything works. Any ideas?

    cmdSelectAuthors = New SqlCommand("Select *, count (column1) as ColumnData from table1 where conditions ", conPubs )

    dtrAuthors = cmdSelectAuthors.ExecuteReader()


    While dtrAuthors.Read()


    Response.Write( dtrAuthors( "ColumnData" ) ) = this should display the total count of rows of column1

    End While Loop

    Thanks in advance

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the SQL query work by itself ?
    Not sure if it'd work without having a group by

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _Nikhil View Post
    Does the SQL query work by itself ?
    Not sure if it'd work without having a group by
    No cant do it in SQL. This is what I am trying to achieve. I have a table that shows different statuses (passed, failed, in progress, pending) I want to show the total count of all rows first then show the total count of each status e.g. total count of passed, total count of failed etc

    So not sure how to do this with data reader

    any ideas?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •