Click here to Skip to main content
12,242,492 members (46,247 online)
   

ASP.NET

 
QuestionApplication Layering Pin
Omersayeed26-Dec-12 3:31
memberOmersayeed26-Dec-12 3:31 
QuestionSyntax error in store procedure Pin
anubhaw.gupta25-Dec-12 23:06
memberanubhaw.gupta25-Dec-12 23:06 
AnswerRe: Syntax error in store procedure Pin
Sravanthid2825-Dec-12 23:21
memberSravanthid2825-Dec-12 23:21 
GeneralRe: Syntax error in store procedure Pin
anubhaw.gupta25-Dec-12 23:40
memberanubhaw.gupta25-Dec-12 23:40 
AnswerRe: Syntax error in store procedure Pin
anubhaw.gupta25-Dec-12 23:45
memberanubhaw.gupta25-Dec-12 23:45 
GeneralRe: Syntax error in store procedure Pin
sathish s26-Dec-12 2:39
membersathish s26-Dec-12 2:39 
GeneralRe: Syntax error in store procedure Pin
Zafar Sultan26-Dec-12 4:31
memberZafar Sultan26-Dec-12 4:31 
Questionid or guid.. which one? Pin
Jassim Rahma25-Dec-12 8:22
memberJassim Rahma25-Dec-12 8:22 
AnswerRe: id or guid.. which one? Pin
Sandeep Mewara25-Dec-12 20:14
mvpSandeep Mewara25-Dec-12 20:14 
AnswerRe: id or guid.. which one? Pin
CommDev25-Dec-12 20:25
memberCommDev25-Dec-12 20:25 
Questionwhy should I care about ExecuteScalar Pin
Jassim Rahma25-Dec-12 6:57
memberJassim Rahma25-Dec-12 6:57 
AnswerRe: why should I care about ExecuteScalar Pin
Sandeep Mewara25-Dec-12 20:30
mvpSandeep Mewara25-Dec-12 20:30 
AnswerRe: why should I care about ExecuteScalar Pin
CommDev25-Dec-12 20:33
memberCommDev25-Dec-12 20:33 
AnswerRe: why should I care about ExecuteScalar Pin
CommDev25-Dec-12 20:40
memberCommDev25-Dec-12 20:40 
Hi,

ExecuteReader

Do not use: when database query is going to provide for sure exactly 1 record. It may be getting record by its id (which is PK in the database) - GetOrderById and such. In this case use ExecuteNonQuery with output parameters.

Use: when database query is going to provide a set of records. It may be search or report.

ExecuteNonQuery

Use: when we are talking about a single database record - in Update, Insert, Delete and Get by Id. In all these cases we can use input/output/input-output parameters. Please note that from the application architecture point of view it is also good practices when your Insert and Update stored procedure returns changed record exactly like Get By Id method does.

ExecuteScalar

Do not use: when database query returns a single value and this value can be defined as parameter in T-SQL. ExecuteNonQuery with output parameter(s) is always preferred in this case since it is more flexible, tomorrow there will be 2 values therefore having ExecuteNonQuery we do not need to change method signatures.

Use: when database query returns a single value and this value cannot be defined as output parameter, because of T-SQL type limitation for variables. For example type image cannot be output parameter in MSSQL.

The most common example for ExecuteScalar is fetching a single image stored in the database and converting it to array of bytes. If you google it - most examples will demonstrate using of ExecuteReader to accomplish image handler, however ExecuteScalar will be more scalable and faster.

Conclusion

Always use ExecuteNonQuery except: when you have a set of records - use ExecuteReader and when you have a single output value that cannot be defined as a parameter - use ExecuteScalar. Hope this helped to clarify something. Enjoy Smile | :)
Comm100 - Leading Live Chat Software Provider

GeneralRe: why should I care about ExecuteScalar Pin
Jassim Rahma28-Dec-12 10:40
memberJassim Rahma28-Dec-12 10:40 
GeneralRe: why should I care about ExecuteScalar Pin
Naveen Katta26-Dec-12 1:10
memberNaveen Katta26-Dec-12 1:10 
Questiona control that should contain html elements Pin
Ali Al Omairi(Abu AlHassan)24-Dec-12 0:01
memberAli Al Omairi(Abu AlHassan)24-Dec-12 0:01 
QuestionRe: a control that should contain html elements Pin
jkirkerx24-Dec-12 14:09
memberjkirkerx24-Dec-12 14:09 
AnswerRe: a control that should contain html elements Pin
Ali Al Omairi(Abu AlHassan)25-Dec-12 20:51
memberAli Al Omairi(Abu AlHassan)25-Dec-12 20:51 
Questioncheckedchange event of gridview in javascript Pin
Ravi_kant23-Dec-12 20:29
memberRavi_kant23-Dec-12 20:29 
AnswerRe: checkedchange event of gridview in javascript Pin
Sampath Kumar Sathiya24-Dec-12 1:20
memberSampath Kumar Sathiya24-Dec-12 1:20 
GeneralRe: checkedchange event of gridview in javascript Pin
Ravi_kant24-Dec-12 8:40
memberRavi_kant24-Dec-12 8:40 
Questionupdated data from gridview Pin
Member 970720723-Dec-12 1:30
memberMember 970720723-Dec-12 1:30 
AnswerRe: updated data from gridview Pin
Ali Al Omairi(Abu AlHassan)24-Dec-12 5:31
memberAli Al Omairi(Abu AlHassan)24-Dec-12 5:31 
AnswerRe: updated data from gridview Pin
Sandeep Mewara25-Dec-12 20:35
mvpSandeep Mewara25-Dec-12 20:35 
Question.net question Pin
Tarani Dutt Joshi22-Dec-12 0:53
memberTarani Dutt Joshi22-Dec-12 0:53 
AnswerRe: .net question Pin
Richard MacCutchan22-Dec-12 1:18
mvpRichard MacCutchan22-Dec-12 1:18 
AnswerRe: .net question Pin
MaulikDusara24-Dec-12 22:38
memberMaulikDusara24-Dec-12 22:38 
AnswerRe: .net question Pin
Sandeep Mewara25-Dec-12 20:33
mvpSandeep Mewara25-Dec-12 20:33 
QuestionWebRequest Pin
cdpsource21-Dec-12 15:16
membercdpsource21-Dec-12 15:16 
Questionwebpage has resulted in too many redirects Pin
Jassim Rahma21-Dec-12 10:46
memberJassim Rahma21-Dec-12 10:46 
AnswerRe: webpage has resulted in too many redirects Pin
jkirkerx22-Dec-12 19:50
memberjkirkerx22-Dec-12 19:50 
GeneralRe: webpage has resulted in too many redirects Pin
Jassim Rahma23-Dec-12 9:36
memberJassim Rahma23-Dec-12 9:36 
GeneralRe: webpage has resulted in too many redirects Pin
jkirkerx23-Dec-12 9:47
memberjkirkerx23-Dec-12 9:47 
GeneralRe: webpage has resulted in too many redirects Pin
Jassim Rahma24-Dec-12 10:10
memberJassim Rahma24-Dec-12 10:10 
GeneralRe: webpage has resulted in too many redirects Pin
jkirkerx24-Dec-12 14:05
memberjkirkerx24-Dec-12 14:05 
Questionpop up on mouse over on a image button Pin
Yasir88721-Dec-12 7:42
memberYasir88721-Dec-12 7:42 
AnswerRe: pop up on mouse over on a image button Pin
AnalogNerd21-Dec-12 10:26
memberAnalogNerd21-Dec-12 10:26 
GeneralRe: pop up on mouse over on a image button Pin
Yasir88721-Dec-12 18:09
memberYasir88721-Dec-12 18:09 
AnswerRe: pop up on mouse over on a image button Pin
n.podbielski22-Dec-12 22:50
membern.podbielski22-Dec-12 22:50 
AnswerRe: pop up on mouse over on a image button Pin
CommDev23-Dec-12 15:35
memberCommDev23-Dec-12 15:35 
Questionasp.net Pin
Nitin Pant20-Dec-12 22:43
memberNitin Pant20-Dec-12 22:43 
AnswerRe: asp.net Pin
Richard MacCutchan20-Dec-12 23:57
mvpRichard MacCutchan20-Dec-12 23:57 
RantRe: asp.net Pin
Richard Deeming21-Dec-12 2:31
memberRichard Deeming21-Dec-12 2:31 
GeneralRe: asp.net Pin
Richard MacCutchan21-Dec-12 3:04
mvpRichard MacCutchan21-Dec-12 3:04 
JokeRe: asp.net Pin
n.podbielski22-Dec-12 22:54
membern.podbielski22-Dec-12 22:54 
AnswerRe: asp.net Pin
J4amieC21-Dec-12 0:26
memberJ4amieC21-Dec-12 0:26 
AnswerRe: asp.net Pin
ProgramFOX21-Dec-12 0:52
memberProgramFOX21-Dec-12 0:52 
AnswerRe: asp.net Pin
CommDev23-Dec-12 15:15
memberCommDev23-Dec-12 15:15 
QuestionProblem with change Gridview cell value Pin
jojoba201120-Dec-12 0:24
memberjojoba201120-Dec-12 0:24 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 30 Apr 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid