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()
Response.Write( dtrAuthors( "ColumnData" ) ) = this should display the total count of rows of column1
End While Loop
Thanks in advance
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
I don't believe it matters what your column is. Rows will always be the same number no matter what column you select. I am not a DBA by any stretch but I work with a few platforms that do and I just select the Table where I wangt to know the Row Count and it tells me.
I am not on my home computer at the moment so I cannot cough up the right SQL terminology. Hopefully someone will soon.
I spoke too soon. I did find an example here at work.
SELECT COUNT(*) FROM test7;
"test7" was my table that I was checking so I would replace that with your table name and give it a twirl.
This topic is now closed. New replies are no longer allowed.