Click here to Skip to main content
15,888,113 members
Home / Discussions / C#
   

C#

 
AnswerRe: Link between dataset and datagrid Pin
Pete O'Hanlon9-Jul-12 22:12
mvePete O'Hanlon9-Jul-12 22:12 
QuestionAccessing HashTable at ButtonClick Level Pin
mrfalk9-Jul-12 13:28
mrfalk9-Jul-12 13:28 
SuggestionRe: Accessing HashTable at ButtonClick Level Pin
Trak4Net9-Jul-12 17:19
Trak4Net9-Jul-12 17:19 
GeneralRe: Accessing HashTable at ButtonClick Level Pin
mrfalk10-Jul-12 6:02
mrfalk10-Jul-12 6:02 
GeneralRe: Accessing HashTable at ButtonClick Level Pin
Trak4Net10-Jul-12 6:54
Trak4Net10-Jul-12 6:54 
AnswerRe: Accessing HashTable at ButtonClick Level Pin
Pete O'Hanlon10-Jul-12 7:09
mvePete O'Hanlon10-Jul-12 7:09 
GeneralRe: Accessing HashTable at ButtonClick Level Pin
mrfalk10-Jul-12 11:14
mrfalk10-Jul-12 11:14 
SuggestionRe: Accessing HashTable at ButtonClick Level Pin
Matt T Heffron10-Jul-12 14:22
professionalMatt T Heffron10-Jul-12 14:22 
As Pete would tell you Dictionary<string, string> is an implementation of a Hashtable that is type-safe, and more efficient (in that no boxing/unboxing is done). Just change the Hashtable in the empData declaration to Dictionary<string, string> (both of them), and remove the .ToString() where you set hashData (it is unnecessary).

Other simple suggestions I'd make for this code:
* You ought to validate that the FieldCount is at least large enough for the number of fields expected, to detect a malformed CSV file.

* If there is any chance you'll need the individual fields later and have to "tear-apart" the concatenated string, I'd suggest creating a class to hold the individual fields as properties and storing that in the Dictionary instead. It can keep the concatenated string as a property, or concatenation can be used where necessary.

* empData.Add(userEIN, ...); will throw an exception if a userEIN value is not unique. You should handle that case, or change to empData[userEIN] = ...; if you just want to keep the last value encountered for the given userEIN.

* You shouldn't need the data array and the use of csv.CopyCurrentRecordTo(data). Your code appears to be using the CsvReader of Fast CSV Reader of Sebastien Lorion[^]. If so, it has the ability to get the field values of the current record by the name found in the headers row. So, I'd suggest making constant strings for the expected header names and use the indexer to get the field values. E.g.:
C#
// Just guessing on the field header texts
const string FirstName = "First Name";
const string MiddleName = "Middle Name";
// etc.
fName = csv[FirstName];
mName = csv[MiddleName];
// etc.

This is much more readable and self-documenting.

* If you use the constants for the expected header names, you should verify that those headers are actually present in the file. You can use, e.g. csv.GetFieldIndex(FirstName) >= 0

* If you don't want to use the header names to lookup the field values, then you can still use named constants for the column index values, instead of the hard-coded column numbers you use now.
C#
const int FirstName = 1;
const int MiddleName = 2;
// etc.
fName = csv[FirstName];
mName = csv[MiddleName];
// etc.


I hope this all helps.
GeneralRe: Accessing HashTable at ButtonClick Level Pin
mrfalk11-Jul-12 10:46
mrfalk11-Jul-12 10:46 
QuestionQuestion... loading unmanaged dll in x64 system Pin
Blubbo9-Jul-12 9:25
Blubbo9-Jul-12 9:25 
AnswerRe: Question... loading unmanaged dll in x64 system Pin
Ian Shlasko9-Jul-12 9:51
Ian Shlasko9-Jul-12 9:51 
GeneralRe: Question... loading unmanaged dll in x64 system Pin
Luc Pattyn9-Jul-12 10:38
sitebuilderLuc Pattyn9-Jul-12 10:38 
Generalodd Custom control size issue Pin
Blubbo9-Jul-12 6:37
Blubbo9-Jul-12 6:37 
GeneralRe: odd Custom control size issue Pin
Pete O'Hanlon9-Jul-12 7:20
mvePete O'Hanlon9-Jul-12 7:20 
GeneralRe: odd Custom control size issue Pin
Blubbo9-Jul-12 8:09
Blubbo9-Jul-12 8:09 
GeneralRe: odd Custom control size issue Pin
Pete O'Hanlon9-Jul-12 8:51
mvePete O'Hanlon9-Jul-12 8:51 
AnswerRe: odd Custom control size issue Pin
Luc Pattyn9-Jul-12 8:58
sitebuilderLuc Pattyn9-Jul-12 8:58 
QuestionAnimation on ContentPresenter ContenSource Changed Pin
ezazazel9-Jul-12 4:16
ezazazel9-Jul-12 4:16 
QuestionHow to return a DataSet reuslt from LINQ class Pin
Ahmed_Worke9-Jul-12 3:57
Ahmed_Worke9-Jul-12 3:57 
QuestionExcel line-column combination chart using C#. Pin
Member 91698878-Jul-12 21:10
Member 91698878-Jul-12 21:10 
AnswerRe: Excel line-column combination chart using C#. Pin
dan!sh 8-Jul-12 22:07
professional dan!sh 8-Jul-12 22:07 
GeneralRe: Excel line-column combination chart using C#. Pin
Member 91698878-Jul-12 22:58
Member 91698878-Jul-12 22:58 
GeneralRe: Excel line-column combination chart using C#. Pin
dan!sh 8-Jul-12 23:19
professional dan!sh 8-Jul-12 23:19 
Questionexcel chart Pin
Member 91698878-Jul-12 20:23
Member 91698878-Jul-12 20:23 
AnswerRe: excel chart Pin
Abhinav S8-Jul-12 20:30
Abhinav S8-Jul-12 20:30 

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.