I am given a CSV file every week that I need to parse and import into SQL. The process I wrote was working great until someone started inputting specific characters. Now it crashes. Here is part of the code that was working:
The group that created the file is using Excel. In some of the fields, they are now inputting text like ""value"". Then they save as *.csv. I can manually go into the CSV and do a find/replace "" with ` and then run my program but it is getting old. They will not change what they are doing and I am forced to deal with it.
I am not 100% familiar with the process I am using but wondering if I can do something like this:
After the while not statement, I was thinking I could use ReadLine() to put the line in a string variable then use Replace to swap out the bad characters. Simple enough. Question now is how to put that string into the ReadFields after "fixing it." Also, would running ReadLine and then ReadFields move the cursor down two records causing a record skip since each states they process the line and move forward? If yes, how to go back a record? Is it as simple as myreader.moveprev or something similar or not possible?
OR
Short of looping through every character in the string and parsing out fields (I know how to do but want to avoid), any other suggestions?
Thanks everyone.
Douglas
Code:
rsNew = New ADODB.Recordset
rsNewSQL = "tbl905Working_EPLS"
rsNew.Open(rsNewSQL, strconn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(myPath)
MyReader.TextFieldType = FileIO.FieldType.Delimited '*****Opts Delimited, FixedWidth,
MyReader.SetDelimiters(",") '*****Use only with Delimited
Dim CurrentRow As String()
While Not MyReader.EndOfData '*****Loop through all rows in the raw file
CurrentRow = MyReader.ReadFields
Dim FldCt As Integer = CurrentRow.Count - 1
If myFlag <> True Then
rsNew.AddNew()
myRow = myRow + 1
End If
Dim CurCt As Integer = 0
For Each newString As String In CurrentRow
myValue = newStringI am not 100% familiar with the process I am using but wondering if I can do something like this:
After the while not statement, I was thinking I could use ReadLine() to put the line in a string variable then use Replace to swap out the bad characters. Simple enough. Question now is how to put that string into the ReadFields after "fixing it." Also, would running ReadLine and then ReadFields move the cursor down two records causing a record skip since each states they process the line and move forward? If yes, how to go back a record? Is it as simple as myreader.moveprev or something similar or not possible?
OR
Short of looping through every character in the string and parsing out fields (I know how to do but want to avoid), any other suggestions?
Thanks everyone.
Douglas