Home All Groups Group Topic Archive Search About

Variable that holds the record count of a result set?

Author
18 Jan 2006 5:23 AM
simon
Hello
is there a variable that is available to me that contains the number
of rows contained in a dataset return from a database call?

have a class that runs a stored proc and returns a dataset/resultset
looking to simply assign an integer this value if it is possible

i'm using (learning) vb.net

thanks again for any help!

Author
18 Jan 2006 8:08 AM
Peter Proost
Hi Simon,

a dataset after it's filled contains one or more tables which you can
address like this:  DataSet.Tables(0)
mostlike the tables contains rows which you can address like this
DataSet.Tables(0).Rows(index) and then again the rows have got a count
property, what you need. So if you want the know the number of rows
contained in a dataset table you can use
DataSet.Tables(tableIndex).Rows.Count()


Hope this helps

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)


Show quoteHide quote
"simon" <m*@here.com> schreef in bericht
news:60krs1l4jo1ugnse4n4ee6vguler5ret3a@4ax.com...
> Hello
> is there a variable that is available to me that contains the number
> of rows contained in a dataset return from a database call?
>
> have a class that runs a stored proc and returns a dataset/resultset
> looking to simply assign an integer this value if it is possible
>
> i'm using (learning) vb.net
>
> thanks again for any help!
>
Author
18 Jan 2006 9:13 AM
Phill W.
"simon" <m*@here.com> wrote in message
news:60krs1l4jo1ugnse4n4ee6vguler5ret3a@4ax.com...

> is there a variable that is available to me that contains the number
> of rows contained in a dataset return from a database call?

Not for the DataSet itself, but on [each of] the DataTable(s) that it
contains, as in

Dim ds as DataSet = GoGetDataAsDataSet()

? ds.Tables( 0 ).Rows

HTH,
    Phill  W.
Author
18 Jan 2006 2:16 PM
simon
thanks guys. i'll try it out tonight
appreciate the replies!
Author
18 Jan 2006 2:47 PM
Chris Petchey
If you are using a dataadapter to populate your dataset, the return
value is the number of rows affected:

Dim r as integer = MyDataAdapter.Fill(MyDataSet)
Debug.Write r.ToString & " rows returned"

OR

If you just want to know howmany rows there will be, change your stored
procedure (have an alternative proc) to do a count rather than return
records

In message <60krs1l4jo1ugnse4n4ee6vguler5re***@4ax.com>, simon
<m*@here.com> writes
>Hello
>is there a variable that is available to me that contains the number
>of rows contained in a dataset return from a database call?
>
>have a class that runs a stored proc and returns a dataset/resultset
>looking to simply assign an integer this value if it is possible
>
>i'm using (learning) vb.net
>
>thanks again for any help!
>

--
Chris Petchey
Author
18 Jan 2006 4:38 PM
simon
thanks chris.  i think this is exactly what i'm looking for.
is it possible to get this count before or after the fill takes place
or can does it need to occur while doing the fill?
examples are always apprecaited by newbies   :-D


On Wed, 18 Jan 2006 14:47:30 +0000, Chris Petchey
<chr***@soltec.demon.co.uk> wrote:

Show quoteHide quote
>Dim r as integer = MyDataAdapter.Fill(MyDataSet)
>Debug.Write r.ToString & " rows returned"