Click here to Skip to main content
15,922,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows service using C# Pin
PIEBALDconsult19-Sep-08 5:20
mvePIEBALDconsult19-Sep-08 5:20 
QuestionExport single Pages from a .indd file Pin
frostii17-Sep-08 0:50
frostii17-Sep-08 0:50 
Questionevent id for system reboot Pin
George_George17-Sep-08 0:44
George_George17-Sep-08 0:44 
QuestionReading csv file into a dataTable Pin
Muammar©17-Sep-08 0:38
Muammar©17-Sep-08 0:38 
AnswerRe: Reading csv file into a dataTable Pin
Ashfield17-Sep-08 1:18
Ashfield17-Sep-08 1:18 
GeneralRe: Reading csv file into a dataTable Pin
Muammar©17-Sep-08 1:25
Muammar©17-Sep-08 1:25 
GeneralRe: Reading csv file into a dataTable Pin
Ashfield17-Sep-08 2:11
Ashfield17-Sep-08 2:11 
AnswerRe: Reading csv file into a dataTable Pin
Colin Angus Mackay17-Sep-08 2:16
Colin Angus Mackay17-Sep-08 2:16 
Muammar© wrote:
What's so wrong with that??


You have more data than columns.


Muammar© wrote:
Any better practice??


Yes, of course.

You are not performing any validation on the data in the reader whatsoever. This is bad, very bad, in fact you can't believe how mind bogglingly massively bad that is....

Always validate your input, whether from a user interface control, a file on a disk or the database. If there is the possibility that the information could be wrong or tampered with you should validate it.

If you are sure the line should be correct you should code in a way that aids debugging. You should extract the line from the file into its own variable, and use the debugger to check what it is.

You should split the string up into another varialbe and use the debugger to tell you what is in that.

You should never just dump the result of a chained set of method calls as the parameter to another method call unless you can GUARANTEE that it won't break or have unexpected results. You cannot make that guarantee, so don't do it!

while (!sr.EndOfStream)
{
    string line = sr.ReadLine();
    string[] tokens = line.Split(',');
    // Do some validation here
    dt.Rows.Add(tokens); // Assumes the validation passed.
}


In the above sample, use the debugger to check what is in line and tokens. Is it what you expect? Is it doing something you didn't expect? What is it doing that is wrong? How would you correct that?


GeneralRe: Reading csv file into a dataTable Pin
Muammar©17-Sep-08 4:53
Muammar©17-Sep-08 4:53 
GeneralRe: Reading csv file into a dataTable Pin
PIEBALDconsult17-Sep-08 5:22
mvePIEBALDconsult17-Sep-08 5:22 
GeneralRe: Reading csv file into a dataTable Pin
Muammar©17-Sep-08 13:37
Muammar©17-Sep-08 13:37 
GeneralRe: Reading csv file into a dataTable Pin
PIEBALDconsult17-Sep-08 16:44
mvePIEBALDconsult17-Sep-08 16:44 
QuestionGet a value ID from a ListBox,which is bind to a Data source. Pin
CJGun16-Sep-08 23:06
CJGun16-Sep-08 23:06 
AnswerRe: Get a value ID from a ListBox,which is bind to a Data source. Pin
CJGun17-Sep-08 19:15
CJGun17-Sep-08 19:15 
Questioncsv imports Pin
rahuladya16-Sep-08 23:05
rahuladya16-Sep-08 23:05 
AnswerRe: csv imports Pin
Giorgi Dalakishvili16-Sep-08 23:14
mentorGiorgi Dalakishvili16-Sep-08 23:14 
GeneralRe: csv imports Pin
Alan Balkany17-Sep-08 4:15
Alan Balkany17-Sep-08 4:15 
GeneralRe: csv imports Pin
Giorgi Dalakishvili17-Sep-08 4:21
mentorGiorgi Dalakishvili17-Sep-08 4:21 
AnswerRe: csv imports Pin
Mohammed Hameed17-Sep-08 1:00
professionalMohammed Hameed17-Sep-08 1:00 
GeneralRe: csv imports Pin
Ashfield17-Sep-08 1:22
Ashfield17-Sep-08 1:22 
Questionset Icon in the Add/Remove program Pin
lune1216-Sep-08 21:50
lune1216-Sep-08 21:50 
AnswerRe: set Icon in the Add/Remove program Pin
Muammar©17-Sep-08 0:53
Muammar©17-Sep-08 0:53 
Questionif a form is already opened ,new form should not been opened Pin
maifs16-Sep-08 21:46
maifs16-Sep-08 21:46 
AnswerRe: if a form is already opened ,new form should not been opened Pin
Nagy Vilmos16-Sep-08 23:43
professionalNagy Vilmos16-Sep-08 23:43 
AnswerRe: if a form is already opened ,new form should not been opened Pin
DaveyM6916-Sep-08 23:55
professionalDaveyM6916-Sep-08 23:55 

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.