Click here to Skip to main content
15,898,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: Readout datagrid in PowerPoint 2010 and insert datas in new PowerPoint slide Pin
Dave Kreskowiak18-Jun-15 10:03
mveDave Kreskowiak18-Jun-15 10:03 
GeneralRe: Readout datagrid in PowerPoint 2010 and insert datas in new PowerPoint slide Pin
Member 1177535418-Jun-15 10:09
Member 1177535418-Jun-15 10:09 
GeneralRe: Readout datagrid in PowerPoint 2010 and insert datas in new PowerPoint slide Pin
Dave Kreskowiak18-Jun-15 10:15
mveDave Kreskowiak18-Jun-15 10:15 
GeneralRe: Readout datagrid in PowerPoint 2010 and insert datas in new PowerPoint slide Pin
Member 1177535418-Jun-15 10:19
Member 1177535418-Jun-15 10:19 
Questionc#(Invalid attempt to call HasRows when reader is closed)occurred when i was using the following query in 3tier Pin
Member 1129409418-Jun-15 1:19
Member 1129409418-Jun-15 1:19 
AnswerRe: c#(Invalid attempt to call HasRows when reader is closed)occurred when i was using the following query in 3tier Pin
Pete O'Hanlon18-Jun-15 1:26
mvePete O'Hanlon18-Jun-15 1:26 
SuggestionRe: c#(Invalid attempt to call HasRows when reader is closed)occurred when i was using the following query in 3tier Pin
Sascha Lefèvre18-Jun-15 1:46
professionalSascha Lefèvre18-Jun-15 1:46 
AnswerRe: c#(Invalid attempt to call HasRows when reader is closed)occurred when i was using the following query in 3tier Pin
OriginalGriff18-Jun-15 2:21
mveOriginalGriff18-Jun-15 2:21 
Sascha is right on all his points:
Your Data layer should be the only one which even knows of the existence of SQL your Business Layer (that you called the Logic Layer) should have no idea about SQL or DataAdapters - that way if you need to change from SQL Server to Access, or MySql or even a text file, the changes are localised to the Data access layer and don't impact any other area.

SQL objects are scarce resources, and you need to ensure that they are Disposed correctly. a using block is the best way to do this as it removes the variable whenever it goes out of scope. You can't return a DataReader from your reader code because the connection has been closed - and a DataReader needs the connection open until you have finished reading the records. Consider using a DataTable instead.

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Your business layer should probably be converting DataTable objects into collections of logical class object instances so that the BL can work with "sensible" objects instead of having to rely on the order of columns in a datatable (or worse a datareader as in your code). Certainly, your presentation layer should be working with "abstract objects" instead of anything like the actual raw data.

Setting the value of a textbox inside a loop will only give you the last row in the datareader - so if you are only getting a single row, use
C#
if (dr.Read())

instead of
C#
while (dr.Read())
It's a lot more obvious what you intended to happen. In this case, I'd want to check that there was only one such item - and log or report a problem if there were more or less.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

Questiondatavisualization - Audiometric chart Pin
Member 1061400017-Jun-15 21:52
Member 1061400017-Jun-15 21:52 
QuestionC# crystal report to generate bill/invoice Pin
shashimk8117-Jun-15 21:13
shashimk8117-Jun-15 21:13 
AnswerRe: C# crystal report to generate bill/invoice Pin
joost.versteegen22-Jun-15 1:28
joost.versteegen22-Jun-15 1:28 
QuestionHow do I access checkbox checked value in a email body built using C#? Pin
Rajesh_198017-Jun-15 10:53
Rajesh_198017-Jun-15 10:53 
AnswerRe: How do I access checkbox checked value in a email body built using C#? Pin
rajeshkasani0517-Jun-15 23:41
rajeshkasani0517-Jun-15 23:41 
GeneralRe: How do I access checkbox checked value in a email body built using C#? Pin
Rajesh_198018-Jun-15 4:40
Rajesh_198018-Jun-15 4:40 
GeneralRe: How do I access checkbox checked value in a email body built using C#? Pin
rajeshkasani0521-Jun-15 23:05
rajeshkasani0521-Jun-15 23:05 
GeneralRe: How do I access checkbox checked value in a email body built using C#? Pin
Rajesh_198022-Jun-15 10:41
Rajesh_198022-Jun-15 10:41 
QuestionGeneric problem of VB.NET Pin
econy17-Jun-15 9:12
econy17-Jun-15 9:12 
AnswerRe: Generic problem of VB.NET Pin
Pete O'Hanlon17-Jun-15 9:19
mvePete O'Hanlon17-Jun-15 9:19 
GeneralRe: Generic problem of VB.NET Pin
econy17-Jun-15 9:31
econy17-Jun-15 9:31 
GeneralRe: Generic problem of VB.NET Pin
econy17-Jun-15 9:37
econy17-Jun-15 9:37 
AnswerRe: Generic problem of VB.NET Pin
Kenneth Haugland17-Jun-15 10:01
mvaKenneth Haugland17-Jun-15 10:01 
AnswerRe: Generic problem of VB.NET Pin
Richard MacCutchan17-Jun-15 21:21
mveRichard MacCutchan17-Jun-15 21:21 
QuestionP/Invoce Rename Struct Field Pin
1011001017-Jun-15 4:43
1011001017-Jun-15 4:43 
AnswerRe: P/Invoce Rename Struct Field Pin
PIEBALDconsult17-Jun-15 4:53
mvePIEBALDconsult17-Jun-15 4:53 
AnswerRe: P/Invoce Rename Struct Field Pin
OriginalGriff17-Jun-15 5:13
mveOriginalGriff17-Jun-15 5:13 

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.