Click here to Skip to main content
16,006,378 members
Home / Discussions / C#
   

C#

 
GeneralRe: better datastructure for storage? Pin
AmandeepSBhatia18-Dec-05 20:41
AmandeepSBhatia18-Dec-05 20:41 
GeneralRe: better datastructure for storage? Pin
AETaylor18-Dec-05 21:09
AETaylor18-Dec-05 21:09 
QuestionStructure conversion Pin
peppepinna16-Dec-05 0:23
peppepinna16-Dec-05 0:23 
AnswerRe: Structure conversion Pin
Nick Parker16-Dec-05 6:02
protectorNick Parker16-Dec-05 6:02 
QuestionCount the number of rows with sqldatareader Pin
Genbox16-Dec-05 0:03
Genbox16-Dec-05 0:03 
AnswerRe: Count the number of rows with sqldatareader Pin
J4amieC16-Dec-05 0:26
J4amieC16-Dec-05 0:26 
GeneralRe: Count the number of rows with sqldatareader Pin
Genbox16-Dec-05 1:00
Genbox16-Dec-05 1:00 
GeneralRe: Count the number of rows with sqldatareader Pin
J4amieC16-Dec-05 1:22
J4amieC16-Dec-05 1:22 
Oh, ok two ways - both exactly the same, but one is a tonne more readable.

You are returning the count as the first column in a select list so you can just go:

while (rdr.Read())<br />
{<br />
      Response.Write(rdr[0].ToString()); // rdr[0] refers to the first column in the resultset<br />
}


However, you can make this much more readable by aliasing the column as a name

SqlCommand cmd = new SqlCommand("SELECT count(*) AS TrainingCount FROM training WHERE userid='genbox'", conn);

now:

while (rdr.Read())<br />
{<br />
      Response.Write(rdr["TrainingCount"].ToString()); // no longer need to know which column number has the count - we refer by name<br />
}



HTH!

-- modified at 7:22 Friday 16th December, 2005
GeneralRe: Count the number of rows with sqldatareader Pin
Genbox17-Dec-05 3:49
Genbox17-Dec-05 3:49 
QuestionTool to detect boxing/unboxing? Pin
LiamD15-Dec-05 23:05
LiamD15-Dec-05 23:05 
AnswerRe: Tool to detect boxing/unboxing? Pin
Heath Stewart16-Dec-05 5:58
protectorHeath Stewart16-Dec-05 5:58 
Questionfree C# 2005 ebook Pin
mehrdadc4815-Dec-05 22:23
mehrdadc4815-Dec-05 22:23 
AnswerRe: free C# 2005 ebook Pin
leppie15-Dec-05 22:37
leppie15-Dec-05 22:37 
GeneralRe: free C# 2005 ebook Pin
HakunaMatada15-Dec-05 23:34
HakunaMatada15-Dec-05 23:34 
AnswerRe: free C# 2005 ebook Pin
albCode16-Dec-05 4:34
albCode16-Dec-05 4:34 
AnswerRe: free C# 2005 ebook Pin
Gulfraz Khan16-Dec-05 6:00
Gulfraz Khan16-Dec-05 6:00 
Answer[Message Removed] Pin
hankjmatt13-Oct-08 21:18
hankjmatt13-Oct-08 21:18 
QuestionURGENT DATAGRID TAB KEY PROBLEM Pin
Greeky15-Dec-05 21:56
Greeky15-Dec-05 21:56 
QuestionAsynchronous call Pin
fmardani15-Dec-05 21:52
fmardani15-Dec-05 21:52 
AnswerRe: Asynchronous call Pin
leppie15-Dec-05 22:41
leppie15-Dec-05 22:41 
GeneralRe: Asynchronous call Pin
fmardani15-Dec-05 22:46
fmardani15-Dec-05 22:46 
QuestionWrite an xml node in a specific position Pin
hellamasta15-Dec-05 21:32
hellamasta15-Dec-05 21:32 
AnswerRe: Write an xml node in a specific position Pin
Heath Stewart15-Dec-05 21:49
protectorHeath Stewart15-Dec-05 21:49 
GeneralRe: Write an xml node in a specific position Pin
hellamasta15-Dec-05 22:17
hellamasta15-Dec-05 22:17 
GeneralRe: Write an xml node in a specific position Pin
Heath Stewart16-Dec-05 5:49
protectorHeath Stewart16-Dec-05 5:49 

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.