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

C#

 
AnswerRe: f PinPopular
OriginalGriff2-Oct-10 23:38
mveOriginalGriff2-Oct-10 23:38 
AnswerRe: f Pin
Nagy Vilmos3-Oct-10 3:40
professionalNagy Vilmos3-Oct-10 3:40 
AnswerRe: f Pin
#realJSOP4-Oct-10 2:05
professional#realJSOP4-Oct-10 2:05 
QuestionImporting .CSV Files To A SQL Database Pin
Roger Wright2-Oct-10 21:41
professionalRoger Wright2-Oct-10 21:41 
AnswerRe: Importing .CSV Files To A SQL Database Pin
dan!sh 2-Oct-10 23:14
professional dan!sh 2-Oct-10 23:14 
AnswerRe: Importing .CSV Files To A SQL Database Pin
Luc Pattyn3-Oct-10 2:51
sitebuilderLuc Pattyn3-Oct-10 2:51 
GeneralRe: Importing .CSV Files To A SQL Database Pin
Roger Wright4-Oct-10 20:04
professionalRoger Wright4-Oct-10 20:04 
GeneralRe: Importing .CSV Files To A SQL Database Pin
Luc Pattyn5-Oct-10 1:55
sitebuilderLuc Pattyn5-Oct-10 1:55 
Hi Roger,

Yes, Regex looks a bit terrifying; I do not suggest to do everything with regexes (others might, I don't); I only suggest to use Regex for rather simple operations that would take quite some code doing it otherwise.

The example suggests the following approach (there may be alternatives, this is my first impression anyway):

1. a Regex could locate the line containing "Total: # records" and extract the record count "RC".

2. another Regex could return a collection of all lines starting with a double quote ("AllLines"); these are the only ones we're interested in.

3. It seems AllLines.Count should equal RC+2, (a header, RC data lines, and a total); if it isn't, raise alarm.

4. Each line in AllLines is supposed to contain the same number of fields. Fields are sepatated by comma, however one should not simply split on comma, as there could be comma's inside the quoted stuff (doesn't happen in your example). PIEBALD has an article on how to handle that.

5. Split each line into a string array holding the individual fields

6. For each field in each line (except first and last line), drop the double quotes, and stuff it into the DataSet (assuming that is what you want).

7. Final check: the last of AllLines should fit the data in the DataSet. If not, raise alarm.


Hope this helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.


AnswerRe: Importing .CSV Files To A SQL Database Pin
PIEBALDconsult3-Oct-10 3:49
mvePIEBALDconsult3-Oct-10 3:49 
QuestionForeach Pin
Saksida Bojan2-Oct-10 6:29
Saksida Bojan2-Oct-10 6:29 
AnswerRe: Foreach Pin
Abhinav S2-Oct-10 6:44
Abhinav S2-Oct-10 6:44 
GeneralRe: Foreach Pin
Saksida Bojan2-Oct-10 6:54
Saksida Bojan2-Oct-10 6:54 
GeneralRe: Foreach Pin
Luc Pattyn2-Oct-10 6:59
sitebuilderLuc Pattyn2-Oct-10 6:59 
GeneralRe: Foreach Pin
Saksida Bojan2-Oct-10 7:06
Saksida Bojan2-Oct-10 7:06 
AnswerRe: Foreach Pin
Luc Pattyn2-Oct-10 6:57
sitebuilderLuc Pattyn2-Oct-10 6:57 
GeneralRe: Foreach Pin
Saksida Bojan2-Oct-10 7:13
Saksida Bojan2-Oct-10 7:13 
GeneralRe: Foreach Pin
Luc Pattyn2-Oct-10 7:38
sitebuilderLuc Pattyn2-Oct-10 7:38 
AnswerRe: Foreach Pin
Henry Minute2-Oct-10 7:05
Henry Minute2-Oct-10 7:05 
GeneralRe: Foreach Pin
Luc Pattyn2-Oct-10 7:35
sitebuilderLuc Pattyn2-Oct-10 7:35 
GeneralRe: Foreach Pin
Henry Minute2-Oct-10 7:44
Henry Minute2-Oct-10 7:44 
GeneralRe: Foreach Pin
Luc Pattyn2-Oct-10 7:45
sitebuilderLuc Pattyn2-Oct-10 7:45 
GeneralRe: Foreach Pin
Henry Minute2-Oct-10 7:46
Henry Minute2-Oct-10 7:46 
GeneralRe: Foreach Pin
Dave Kreskowiak2-Oct-10 7:39
mveDave Kreskowiak2-Oct-10 7:39 
GeneralRe: Foreach Pin
Henry Minute2-Oct-10 7:45
Henry Minute2-Oct-10 7:45 
GeneralRe: Foreach Pin
Dave Kreskowiak2-Oct-10 10:04
mveDave Kreskowiak2-Oct-10 10:04 

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.