Click here to Skip to main content
15,914,410 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Debugging Pin
AndyG28-Aug-02 6:45
AndyG28-Aug-02 6:45 
GeneralRe: SQL Debugging Pin
Shaun Wilde28-Aug-02 8:28
Shaun Wilde28-Aug-02 8:28 
GeneralRe: SQL Debugging Pin
notadood28-Aug-02 8:57
notadood28-Aug-02 8:57 
GeneralODBC.NET and Excel Pin
Knappen27-Aug-02 1:30
Knappen27-Aug-02 1:30 
GeneralRe: ODBC.NET and Excel Pin
Paul Riley27-Aug-02 4:55
Paul Riley27-Aug-02 4:55 
GeneralRetrieving QTY of records on a SQLClient Pin
toki24-Aug-02 11:30
toki24-Aug-02 11:30 
GeneralRe: Retrieving QTY of records on a SQLClient Pin
James T. Johnson24-Aug-02 13:50
James T. Johnson24-Aug-02 13:50 
GeneralRe: Retrieving QTY of records on a SQLClient Pin
Paul Ingles25-Aug-02 4:24
Paul Ingles25-Aug-02 4:24 
You can always execute a SELECT COUNT statement before the main statement, that will return the number of rows.

i.e. if your usual where clause is something like

SELECT * FROM OrderDetails WHERE CustomerID=59

You can get the number of rows by executing
SELECT COUNT(OrderID) FROM OrderDetails WHERE CustomerID=59


If you execute that using ExecuteScalar, you'll get the number of rows that will be returned by that query.

Incidentally, if there's a chance that this number could change in-between executing the two queries, or you just want to be extra careful, you'll want to execute both queries as part of the same transaction, ensuring that the number of records doesn't change as a result of someone else inserting/deleting records from the table.

Alternatively, you could consider taking the data to a DataSet first, since that's held in-memory you only execute the query once, and I'm pretty sure there must be a way to obtain the number of rows. This will have the usual advantages/disadvantages of using a DataSet as opposed to a DataReader.

--
Paul
"I need the secure packaging of Jockeys. My boys need a house!"
- Kramer, in "The Chinese Woman" episode of Seinfeld

MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446

GeneralRe: Retrieving QTY of records on a SQLClient Pin
toki28-Aug-02 16:06
toki28-Aug-02 16:06 
QuestionWhats wrong with this picture? Pin
Robby22-Aug-02 3:07
Robby22-Aug-02 3:07 
AnswerRe: Whats wrong with this picture? Pin
notadood22-Aug-02 3:12
notadood22-Aug-02 3:12 
GeneralRe: Whats wfdgwith this picture? Pin
Anonymous22-Aug-02 9:18
Anonymous22-Aug-02 9:18 
AnswerRe: Whats wrong with this picture? Pin
Bruce Duncan22-Aug-02 9:34
Bruce Duncan22-Aug-02 9:34 
GeneralDleDbDataAdapter and DSNs Pin
thiggs21-Aug-02 4:02
thiggs21-Aug-02 4:02 
GeneralSQL - SELECT DISTINCT myfield Pin
Tim Rymer20-Aug-02 4:59
Tim Rymer20-Aug-02 4:59 
GeneralRe: SQL - SELECT DISTINCT myfield Pin
Mazdak20-Aug-02 9:02
Mazdak20-Aug-02 9:02 
GeneralThat doesnt work. Pin
Tim Rymer20-Aug-02 9:48
Tim Rymer20-Aug-02 9:48 
GeneralRe: That doesnt work. Pin
DanielO21-Aug-02 3:21
DanielO21-Aug-02 3:21 
GeneralMinor addition Pin
Anonymous21-Aug-02 4:38
Anonymous21-Aug-02 4:38 
GeneralRe: That doesnt work. Pin
Tim Rymer22-Aug-02 3:51
Tim Rymer22-Aug-02 3:51 
GeneralRe: That doesnt work. Pin
Mazdak21-Aug-02 4:25
Mazdak21-Aug-02 4:25 
GeneralRe: That doesnt work. Pin
notadood26-Aug-02 7:44
notadood26-Aug-02 7:44 
GeneralCheck (create table) error Pin
Hans Ruck20-Aug-02 0:40
Hans Ruck20-Aug-02 0:40 
Generalsp_OAMethod type mismatch error Pin
Le centriste19-Aug-02 10:36
Le centriste19-Aug-02 10:36 
GeneralODBC & SQL - Modify the "Table" name in Excel Pin
Stefan_L_0119-Aug-02 10:32
Stefan_L_0119-Aug-02 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.