By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,160 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,160 IT Pros & Developers. It's quick & easy.

How to count no of record ?

P: n/a
In my store procedure , i will select * from myTable, and I will while-loop
the result by using datareader in vb.net .
Now, Can I know the number of records before I while-loop the resut ??

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
AFAIK, you won't know the number of records. You can change the query to
say:

Select *, Count(*) from myTable which will also give you the count.

hope that helps..
Imran.

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
In my store procedure , i will select * from myTable, and I will
while-loop
the result by using datareader in vb.net .
Now, Can I know the number of records before I while-loop the resut ??

Nov 21 '05 #2

P: n/a
CT
Not unless you have the row count returned as a different result set, making
the stored procedure return two results; the row count and the actual rows.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
In my store procedure , i will select * from myTable, and I will
while-loop
the result by using datareader in vb.net .
Now, Can I know the number of records before I while-loop the resut ??

Nov 21 '05 #3

P: n/a
Could you give me a little sample , how to return two result ???
Thanks a lot
"CT" <ca******@spammersgoawaydotnetservices.biz> 秎ン
news:eX**************@TK2MSFTNGP14.phx.gbl い级糶...
Not unless you have the row count returned as a different result set, making the stored procedure return two results; the row count and the actual rows.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
In my store procedure , i will select * from myTable, and I will
while-loop
the result by using datareader in vb.net .
Now, Can I know the number of records before I while-loop the resut ??


Nov 21 '05 #4

P: n/a
CT
Sure, do something like this:

SELECT COUNT(*) FROM TableName;
SELECT * FROM TableName

Once results have been returned to the client, read the scalar value in the
first resultset, and move the "real" data in the second resultset using the
NextResult method of the datareader.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Could you give me a little sample , how to return two result ???
Thanks a lot
"CT" <ca******@spammersgoawaydotnetservices.biz> 秎ン
news:eX**************@TK2MSFTNGP14.phx.gbl い级糶...
Not unless you have the row count returned as a different result set,

making
the stored procedure return two results; the row count and the actual

rows.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
> In my store procedure , i will select * from myTable, and I will
> while-loop
> the result by using datareader in vb.net .
> Now, Can I know the number of records before I while-loop the resut ??
>
>
>



Nov 21 '05 #5

P: n/a
why not put the * and count(*) in the same sql so you don't hit the server
twice?

select *, Count(*) from myTable

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
Sure, do something like this:

SELECT COUNT(*) FROM TableName;
SELECT * FROM TableName

Once results have been returned to the client, read the scalar value in
the first resultset, and move the "real" data in the second resultset
using the NextResult method of the datareader.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Could you give me a little sample , how to return two result ???
Thanks a lot
"CT" <ca******@spammersgoawaydotnetservices.biz> 秎ン
news:eX**************@TK2MSFTNGP14.phx.gbl い级糶...
Not unless you have the row count returned as a different result set,

making
the stored procedure return two results; the row count and the actual

rows.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
> In my store procedure , i will select * from myTable, and I will
> while-loop
> the result by using datareader in vb.net .
> Now, Can I know the number of records before I while-loop the resut ??
>
>
>



Nov 21 '05 #6

P: n/a
disregard my previous msg - I wasn't thinking :(

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
Sure, do something like this:

SELECT COUNT(*) FROM TableName;
SELECT * FROM TableName

Once results have been returned to the client, read the scalar value in the first resultset, and move the "real" data in the second resultset using the NextResult method of the datareader.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Could you give me a little sample , how to return two result ???
Thanks a lot
"CT" <ca******@spammersgoawaydotnetservices.biz> 秎ン
news:eX**************@TK2MSFTNGP14.phx.gbl い级糶...
Not unless you have the row count returned as a different result set,

making
the stored procedure return two results; the row count and the actual

rows.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
> In my store procedure , i will select * from myTable, and I will
> while-loop
> the result by using datareader in vb.net .
> Now, Can I know the number of records before I while-loop the resut ?? >
>
>



Nov 21 '05 #7

P: n/a
CT
Heck, it's Friday, right? ;-)

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Imran Koradia" <no****@microsoft.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
disregard my previous msg - I wasn't thinking :(

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
Sure, do something like this:

SELECT COUNT(*) FROM TableName;
SELECT * FROM TableName

Once results have been returned to the client, read the scalar value in

the
first resultset, and move the "real" data in the second resultset using

the
NextResult method of the datareader.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
> Could you give me a little sample , how to return two result ???
> Thanks a lot
>
>
> "CT" <ca******@spammersgoawaydotnetservices.biz> 秎ン
> news:eX**************@TK2MSFTNGP14.phx.gbl い级糶...
>> Not unless you have the row count returned as a different result set,
> making
>> the stored procedure return two results; the row count and the actual
> rows.
>>
>> --
>> Carsten Thomsen
>> Enterprise Development with VS .NET, UML, and MSF
>> http://www.apress.com/book/bookDisplay.html?bID=105
>> "Agnes" <ag***@dynamictech.com.hk> wrote in message
>> news:u1**************@TK2MSFTNGP09.phx.gbl...
>> > In my store procedure , i will select * from myTable, and I will
>> > while-loop
>> > the result by using datareader in vb.net .
>> > Now, Can I know the number of records before I while-loop the resut ?? >> >
>> >
>> >
>>
>>
>
>



Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.