Reading in a csv file

supersal666

Member
Joined
Aug 29, 2007
Messages
10
Location
Manchester, UK
Programming Experience
3-5
Hi everyone, I have a problem when I read in a csv file, split the string by delimeters and put into a sql database. The code works fine apart from when there is a # symbol in the csv file.

The csv file contains data from scanning questionnare forms and gives an error (error #3100) when the scanner cannot determine the checkbox that has been filled in.

Does anybody know why the # causes problems. The data is put into the database up until the # sign. Does the # sign have a special meaning when reading from csv files?

Thanks
Sally
 
The # has no effect in the csv file, csv files are only concerned with commas

What's the code that you're using when the program gives an error on the #
 
Here is the part of my code which gets the data from the csv file:

VB.NET:
Dim objSRFile As StreamReader
        Dim strInput, arrStrInput() As String
        Dim intCurrPos As Integer
        Dim ref, greeted, catalogue, fitProduct, itemsNotOffered, shopAgain, recommend, age, lastTiles, hearOfUs, hearOfUs1, hearOfUs2, hearOfUs3, hearOfUs4, hearOfUs5, service, comments As String
          Dim fileName = "customersatisfaction.csv"
        Try
            'Open the file that has been downloaded from TradePro
            objSRFile = File.OpenText("C:\FeedbackForm\fromScanned\customersatisfaction.csv")
            While objSRFile.Peek <> -1
                strInput = objSRFile.ReadLine
                arrStrInput = Split(strInput, ",", , CompareMethod.Text)
                           For intCurrPos = 0 To arrStrInput.Length
                    Select Case intCurrPos
                        ' get each field and set them as individual vars
                        Case 0
                            ref = arrStrInput(intCurrPos)
                        Case 1
                            greeted = arrStrInput(intCurrPos)
                        Case 2
                            catalogue = arrStrInput(intCurrPos)
                        Case 3
                            fitProduct = arrStrInput(intCurrPos)
                        Case 4
                            itemsNotOffered = arrStrInput(intCurrPos)
                        Case 5
                            shopAgain = arrStrInput(intCurrPos)
                        Case 6
                            recommend = arrStrInput(intCurrPos)
                        Case 7
                            age = arrStrInput(intCurrPos)
                        Case 8
                            lastTiles = arrStrInput(intCurrPos)
                        Case 9
                            hearOfUs = arrStrInput(intCurrPos)
                        Case 10
                            hearOfUs1 = arrStrInput(intCurrPos)
                        Case 11
                            hearOfUs2 = arrStrInput(intCurrPos)
                        Case 12
                            hearOfUs3 = arrStrInput(intCurrPos)
                        Case 13
                            hearOfUs4 = arrStrInput(intCurrPos)
                        Case 14
                            hearOfUs5 = arrStrInput(intCurrPos)
                        Case 15
                            service = arrStrInput(intCurrPos)
                        Case 16
                            comments = arrStrInput(intCurrPos)
                    End Select         
                Next

Is there anything that you can see here

Thanks
Sally
 
Last edited by a moderator:
I don't see anything that jumps out as being a problem.

Everything in the text file is being handled as string(s) so the '#' character wouldn't be a problem. I also see that the code posted isn't the entire section either.

Have you verified that the text file has all the "fields" ?
 
I am such a doofus!

Basically I am a wally. I had the datatypes to accept only 10 chars. When the error was trying to insert into the database it was failing because it was 11 chars long!
 
Back
Top