|
You can't, because it's a forward-only cursor.
Paul Watson wrote:
But now I have just realised I cannot figure out how to get a row count from the reader without actually looping through it, which bites because I need the rowcount before I loop so that I can initialise a collection array. Doh.
You can create an ArrayList and, at the end, use the ArrayList.CopyTo method for copying it to typed array.
Since this will only copy object references, not the actual values, it's very fast. Normally much, much faster than a SQL count.
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
Daniel Turini wrote:
You can't, because it's a forward-only cursor.
I know, was hoping someone had some trick up their sleave
Daniel Turini wrote:
Since this will only copy object references, not the actual values, it's very fast. Normally much, much faster than a SQL count.
Great idea, thanks Daniel.
|
|
|
|
|
If you had used an SQL COUNT() function before you retrieved the it probably wouldn't be accurate either (atleast not in a multiuser enviornment), unless it's run in a serializable transaction.
The SqlDataReader streams the data and will reflect all the changes in the database until the data has passed through the reader. So records could easily be added or deleted after the count was issued and while the reader is processing.
Morty
|
|
|
|
|
Morten Abrahamsen wrote:
If you had used an SQL COUNT() function before you retrieved the it probably wouldn't be accurate either (atleast not in a multiuser enviornment), unless it's run in a serializable transaction.
Nice point
Morten Abrahamsen wrote:
The SqlDataReader streams the data and will reflect all the changes in the database until the data has passed through the reader. So records could easily be added or deleted after the count was issued and while the reader is processing.
This is not true: The .NET framework does not provides support for server-side cursors, only client-side cursors. This way, only deleted records would be noticed by SqlDataReader.
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
What do you base this on ?
AFAIK, the data is streamed directly from the server, and even though it doesn't utilize server-side cursors it doesn't precalculate the entire dataset (it's streamed ... standard SQL Server dataset processing...). So if records are appended during the read it should be reflected.
However I could be wrong, so if you have any docs / references please post them
.NET SDK:
Changes made to a resultset by another process or thread while data is being read may be visible to the user of the SqlDataReader. However, the precise behavior is timing dependent.
Morty
|
|
|
|
|
|
Well... the SqlDataReader is by no means a client side cursor... it's simply a TDS parser. That's what the dataset is for
Would be cool to check out the theory though... (how much locking does the TDS generator really support...) but as usual, I would probably never find the time.
Morty
|
|
|
|
|
Morten Abrahamsen wrote:
Well... the SqlDataReader is by no means a client side cursor... it's simply a TDS parser. That's what the dataset is for
Well, if it is a TDS parser it should be pretty fast! I think you're right, but some Anakrino hacking may solve this issue
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
Hehe... been there
However, this is not an issue dependant on the .NET SQL Client layer.
It's a question of how the SQL Server handles standard query processing.
If you issue a select query with a 100.000 record resultset, it would be returned as a datastream (TDS) to the client.
I would think that if there is no isolation (tx) there would just be a read lock on the current row (or index key) and not on the table, so records could easily be added or deleted. So if I'm correct the SQL Server would just read the data page by page and never precalculate the total amount and lock it. Hence the "imagined resultset" could be radically (add/delete) changed during the processing (which could take time), and a prior Count would be useless.
Just my 2c
|
|
|
|
|
I deduced the inserts would not be visible and deletes would by this: what would happen with a forward only cursor if I do a SELECT ... ORDER BY table_field and someone inserts data before my current cursor position?
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
I agree. If you do an order by and that order by is not the clustered index SQL Server would have to preprocess the entire dataset. (meaning the keys .. not necessarily the data).
However, it would be interesting to see what happens if you don't use a postprocessing instruction. (ORDER BY, GROUP BY, UNION, DISTINCT etc)
Morty
|
|
|
|
|
Hi I have the following table schema
Order(orderID, orderDate, creditCardNo, etc.....)
OrderedItem(OrderID(pk), ProductID(pk) )
Product(productId, productName ....etc.._
In access, when i delete the product from the Product table, if it is associated with a particular OrderedItem then i can not delete it, else i will be able to delete it.
However, I want to set it to ON DELETE SET NULL the ProductID in the OrderedItem
How will i do it?
Thanks
|
|
|
|
|
Hi,
I am trying to access password and aliases or for that matter every thing related to microsoft exchange users i am able to retrieve only usernames using mapi.session object,
Please help in retrieving other things if any body has code plesae post it here.
I have tried using ADSI also.
Thanks,
Amit Gupta
|
|
|
|
|
I would be very surprised if you were able to retrieve the user password using ANY form of API
|
|
|
|
|
I'd like to query and XML file with an SQL statement. Can this be done, or do I have to use XPath stuff? I've been perusing all sorts of CP code and MSDN stuff, and I can't seem to find an example of this, but I can't seem to find something that says I can't do this either.
Also, can the queries consist of a table join?
Thanks,
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator.
|
|
|
|
|
Marc Clifton wrote:
Can this be done, or do I have to use XPath stuff?
I believe you have to use XPath, however SQL Server can return your "recordset" as an XML document. If that is any help to you.
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
|
|
Is it possible create table WITH MY PROGRAM useing ADO.NET?
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Yes
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Yes, the easiest way is to issue a "CREATE TABLE ..." command
Dave.
|
|
|
|
|
dougieb wrote:
An extra $20 if you add parameters for 'first record to return from set', 'how many to return from set'
Save your $20 bucks and put a SELECT TOP X, where X is the record #.
No one will be able to give you a working solution without the tables. All you'll get is untested queries, and probably none will work and all of them will be slow.
Or, if you want, buy me a Amazon certificate.
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
I had a correct answer, so I tried to delete the thread as not to bug anyone else, but to no avail.
Thank you.
|
|
|
|
|
dougieb wrote:
As for the absence of tables, I'm pretty sure that generic tables could be made for testing purposes, or I figured that there would be some puzzle enthusiast who would just redo the syntax.
All I can say is good luck
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
I guess for a guy who's going to earn $60 it will be quite helpful to know data layout (tables, columns, column types, indices). Or do you think $60 should cover all guessing work too?
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|