Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
AnswerRe: AND and OR with expressions Pin
enginço15-Jul-08 4:19
enginço15-Jul-08 4:19 
QuestionC# Datagridview Pin
Member 364449715-Jul-08 0:57
Member 364449715-Jul-08 0:57 
AnswerRe: C# Datagridview Pin
benjymous15-Jul-08 1:08
benjymous15-Jul-08 1:08 
Questionto get record count of SQL Query...? Pin
Raheem MA15-Jul-08 0:52
Raheem MA15-Jul-08 0:52 
AnswerRe: to get record count of SQL Query...? Pin
mark_w_15-Jul-08 0:57
mark_w_15-Jul-08 0:57 
AnswerRe: to get record count of SQL Query...? Pin
Nirandas15-Jul-08 1:22
Nirandas15-Jul-08 1:22 
GeneralRe: to get record count of SQL Query...? Pin
Raheem MA15-Jul-08 1:58
Raheem MA15-Jul-08 1:58 
AnswerRe: to get record count of SQL Query...? Pin
Wendelius15-Jul-08 6:45
mentorWendelius15-Jul-08 6:45 
Hi,

Without any more info about the problem (what database, connection type etc.), it's hard to give any exact answer, but some ideas might be useful:

1. If you execute a select statement using SQLCommand (or corresponding class) and then get the row count from returned SQLDataReader class using property ReccordsAffected. You get the actual count of returned rows without any loop.

2. If you don't want to manipulate the original query, you can still construct a nested query. For example:
string originalQuery = "SELECT x,y FROM z WHERE x=l";
string countQuery = "SELECT COUNT(*) FROM (" + originalQuery ")";
SQLCommand countCommand = new SQLCommand;

countCommand.CommandText = countQuery;
...


This would result in a query which executes the original query, creates a result set which is then counted. So this means it returns only one row and one column, the record count.

This solution varies between different databases, because all databases cannot handle nested result sets.

3. Create a stored procedure into the database which actually executes the statement and returns the row count. Something like this semi-code

PROCEDURE RowCount(IN statement, OUT rows)
BEGIN
   EXECUTE statement;
   rows = SQL%ROWCOUNT;
END;


4. If possible, ask the datatabase optimizer how many rows it thinks may be returned (using procedure). This implementation is fully database-dependent.


Hope this helps,

Mika
QuestionUsing value in string variable as "type" Pin
dan!sh 15-Jul-08 0:51
professional dan!sh 15-Jul-08 0:51 
GeneralRe: Using value in string variable as "type" Pin
dan!sh 15-Jul-08 0:59
professional dan!sh 15-Jul-08 0:59 
AnswerRe: Using value in string variable as "type" Pin
S. Senthil Kumar15-Jul-08 9:08
S. Senthil Kumar15-Jul-08 9:08 
QuestionDisable screensaver through C# app with out admin rights Pin
CNReddy15-Jul-08 0:31
CNReddy15-Jul-08 0:31 
AnswerRe: Disable screensaver through C# app with out admin rights Pin
Simon P Stevens15-Jul-08 1:29
Simon P Stevens15-Jul-08 1:29 
AnswerRe: Disable screensaver through C# app with out admin rights Pin
Thomas Stockwell15-Jul-08 8:29
professionalThomas Stockwell15-Jul-08 8:29 
QuestionDoes Unified communication client api works with any thing other than Office Commnication Server.... Pin
Atif Ali Bhatti15-Jul-08 0:30
Atif Ali Bhatti15-Jul-08 0:30 
AnswerRe: Does Unified communication client api works with any thing other than Office Commnication Server.... Pin
Atif Ali Bhatti15-Jul-08 0:46
Atif Ali Bhatti15-Jul-08 0:46 
QuestionDateTime format Error WMI Pin
Mogaambo15-Jul-08 0:12
Mogaambo15-Jul-08 0:12 
AnswerRe: DateTime format Error WMI Pin
leppie15-Jul-08 0:42
leppie15-Jul-08 0:42 
Questionusing IsNumeric Function in c# Pin
sumit703414-Jul-08 23:53
sumit703414-Jul-08 23:53 
AnswerRe: using IsNumeric Function in c# Pin
Mogaambo15-Jul-08 0:16
Mogaambo15-Jul-08 0:16 
AnswerRe: using IsNumeric Function in c# Pin
stancrm15-Jul-08 0:19
stancrm15-Jul-08 0:19 
GeneralRe: using IsNumeric Function in c# Pin
sumit703415-Jul-08 0:43
sumit703415-Jul-08 0:43 
GeneralRe: using IsNumeric Function in c# Pin
Le centriste15-Jul-08 1:59
Le centriste15-Jul-08 1:59 
GeneralRe: using IsNumeric Function in c# Pin
leppie15-Jul-08 2:48
leppie15-Jul-08 2:48 
GeneralRe: using IsNumeric Function in c# Pin
Le centriste15-Jul-08 2:53
Le centriste15-Jul-08 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.