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

C#

 
Questionf Pin
Sajid Maqbool2-Oct-10 23:34
Sajid Maqbool2-Oct-10 23:34 
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 
Good points, all of them. As for a sample:

Date Range = Yesterday (09/01/2010)
Time Zone = MST
Sign Convention = GEN + LOAD + OTHER +
Include Zero = Yes
Execution Time: 09/02/2010 07:00  CST

"Zone = RMS / AMPS"

"Date","Meter","HE1","HE2","HE3","HE4",...,"HE24","On Peak","Off Peak","Total"
"09/01/2010","BCI891 ","0.000","0.000","0.000","0.000",...,"0.000","45.000","0.000","45.000"
"","DAD348 Out","0.000","0.000","0.000","0.000",...,"4.634","4.382","75.264","9.016","84.280"
"","NON921A Out","-6.200","-5.800","-5.600","-5.300",...,"-7.300","-150.700","-49.200","-199.900"
"","TOP928 In","0.000","0.000","0.000","0.000",...,"0.000","0.000","0.000","0.000"
"","TOP928 Out","7.490","6.940","6.740","6.440",...,"8.750","179.920","58.980","238.900"
"09/01/2010","","1.290","1.140","1.140","1.140",...,"5.832","149.484","18.796","168.280"
Total: 5 records


The above is typical, exported from Excel as a .csv file and emailed to me by an automated system. The headings HEx mean "Hour Ending", so I edited out most of them, as they aren't relevant to seeing the pattern. I've taken your suggestion and read up on Regex - what a pain! I don't know when it changed, but it's no longer possible to print "this topic and all sub-topics" from the VS2008 Help system.

In looking at it tonight, I think I see an approach that is fairly simple. As I read each line, I can look at the first 4 or 5 characters and tell what kind of line it is, dumping any that aren't data lines. The String.Length() function will make it easy to drop blank lines, too. A line that begins with a date is then either the beginning of data, or the summary line with column totals, and a little string footwork can patch the date into the lines that are missing that item so that they all have the same format. A Regex will be handy to extract the number of lines from the last line, just to make sure I've got all of it in my result set.


I'm not sure what to do with all the data values that should be numerics - I'd like to strip all the quotes out before importing to a dataset, excepting the text containing the meter name, to save having to do conversions from string to float after I import them, but that seems like more than it's worth. I hate to hardcode formats into the program, just in case the format changes one day, but I don't see any way around it.

Thanks for the suggestions! Big Grin | :-D
Will Rogers never met me.

GeneralRe: Importing .CSV Files To A SQL Database Pin
Luc Pattyn5-Oct-10 1:55
sitebuilderLuc Pattyn5-Oct-10 1:55 
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 

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.