|
-
Dec 30th, 2002, 02:09 PM
#1
Thread Starter
Member
Row count
I need to return the number of rows produced into the datagrid by this code. Can someone give me a push in the right direction?
Thanks much....Ooogs
Dim myQuery As String = "SELECT * FROM [tbl * F002 > 4 J] WHERE MUFLID2 =" & Chr(39) & ddlWho.SelectedItem.Text & Chr(39) & " ORDER BY" & sortee
OleDbConnection1.Open()
Dim cmd As New OleDb.OleDbCommand()
cmd.Connection = OleDbConnection1
cmd.CommandText = myQuery
Dim datareader As OleDb.OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgF002.DataSource = datareader
dgF002.DataBind()
-
Dec 30th, 2002, 03:02 PM
#2
There is a programmatical way, but I usually just run the same select you have, but instead of
SELECT * ...
I use
SELECT Count(*) ...
Then, I read row1,col1 to get the count and then close the recordset, run the SELECT * and press on.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Dec 30th, 2002, 03:12 PM
#3
Thread Starter
Member
Do you mean to do something like this?
Dim cmd As New OleDb.OleDbCommand()
cmd.Connection = OleDbConnection1
Dim myCount As String = "SELECT count(*) FROM [tbl * F002 > 4 J] WHERE MUFLID2 =" & Chr(39) & ddlWho.SelectedItem.Text
OleDbConnection1.Open()
cmd.CommandText = myCount
Dim datareader As OleDb.OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
(Here is where I guess I need to reference the count(*))
Dim myQuery As String = "SELECT * FROM [tbl * F002 > 4 J] WHERE MUFLID2 =" & Chr(39) & ddlWho.SelectedItem.Text & Chr(39) & " ORDER BY" & sortee
OleDbConnection1.Open()
cmd.CommandText = myQuery
datareader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgF002.DataSource = datareader
dgF002.DataBind()
OleDbConnection1.Close()
If so, how would I then reference the count number I obtained in the first block?
Ooogs
-
Dec 30th, 2002, 04:55 PM
#4
Correct.
Something like:
Code:
if not objReader.Read() Then
'Oh My. Something went wrong...
return false
end if
myCount = objReader.Items(0)
objReader.Close()
Just FYI. This is actually better than trying to get the row count from the objReader itself for the following reason.
If you attempted to get the reader's row count, you would have to fetch to the end of the recordset first in order to assure you that the dataset has dumped you the entire result set (in order to get an accurate count) which also means that you have to open the recordset with a backward-readable cursor, which in turn uses more environment space and is a slower cursor.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|