[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

OdbcDataReader and number of returend rows

Marc Fauser

4/30/2002 6:06:00 PM

I connect to my database:
Dim SQLCommand As OdbcCommand = New OdbcCommand()
Dim drDB As OdbcDataReader
Dim SQLConnection1 As OdbcConnection = New OdbcConnection([...])
drDB = SQLCommand.ExecuteReader()

Befor I want to go to the while loop, I want to get the number of rows,
returend by
the database. Without the number, I cannot make a percentbar. I don't want
to use
the DataSet.

While (drDB.Read)
End While


Best regards,
FAUSER AG
Marc Fauser


........................................................
FAUSER AG
organisation@software

Gutenbergstr. 5
82205 Gilching

Fon: +49 (0)8105 / 26790
Fax: +49 (0)8105 / 26797
Web: http://www.fau...
........................................................

[gem. Par.28Abs.3 BDSG ist die Verwendung der Adresse für Werbung untersagt]


5 Answers

Markus Seger

4/30/2002 6:35:00 PM

0

"Marc Fauser" <marc.fauser.n.o.s.p.a.m@fauser-ag.com> wrote in message
news:#mSpPCG8BHA.2312@tkmsftngp04...
> I connect to my database:
> Dim SQLCommand As OdbcCommand = New OdbcCommand()
> Dim drDB As OdbcDataReader
> Dim SQLConnection1 As OdbcConnection = New OdbcConnection([...])
> drDB = SQLCommand.ExecuteReader()
>
> Befor I want to go to the while loop, I want to get the number of rows,
> returend by
> the database. Without the number, I cannot make a percentbar. I don't want
> to use
> the DataSet.

In C#, I'd do it as follows:

myCommand.CommandText = "select count(*) from myTable";
int rowCnt = (int) myCommand.ExecuteScalar();

Should be easy to transfer this to VB. Hope this helps.

Markus


(Steven Bras [MS])

4/30/2002 9:59:00 PM

0

Marc Fauser

5/1/2002 2:00:00 PM

0

Steven Bras [MS] <stevenbr@online.microsoft.com> wrote:

> See Markus' excellent idea below; unfortunately, because of the way
> the DataReader is designed, the number of rows it will ultimately
> return is not available. This object opens a forward-only recordset,
> retrieving rows one by one until there are no more. It can't tell you
> how many rows there are until it's entirely done reading them.

Is it possible to change e.g. to OdbcDataAdapter or something else?
I don't need the forward-only-recordset. Sometimes I have to move
back in my recordset.

Best regards,
Marc Fauser


(Steven Bras [MS])

5/1/2002 8:04:00 PM

0

Marc Fauser

5/2/2002 3:08:00 PM

0

Steven Bras [MS] <stevenbr@online.microsoft.com> wrote:

> Yes, you can use an ODBCConnection, and an ODBCDataAdapter to fill a
> dataset. You can then move forward and backward through that dataset
> as necessary. Here's an example in VB:
>
> Dim oCn As New
> SqlConnection("server=(local);database=northwind;user id=me;")
> Dim oDa As New SqlDataAdapter("SELECT * FROM Customers", oCn)
> Dim oDs As New DataSet()
>
> oDa.Fill(oDs, "Customers")
>
> Dim oDr As DataRow
>
> For Each oDr In oDs.Tables("Customers").Rows
> ListBox1.Items.Add(oDr.Item(0))
> Next
>
> This sample loads a value from the dataset into a listbox, for
> example.

Ok. Your example works fine if you use SqlConnection and SqlDataAdapter.
But I cannot get it to work with OdbcConnection as OdbcDataAdapter. Can
you give me an example for this one?

Best regards,
Marc Fauser