Validate a CSV file with VB.NET

Last post 03-26-2009 8:36 AM by Ayan_Biswas_79. 9 replies.

Sort Posts:

  • Validate a CSV file with VB.NET

    01-23-2009, 5:45 AM

     Hi all,

    I need to validate a csv file before it going to upload to a table.(Oracle Database)

    I need to validate the following:

    1) Needs to Validate the single quote and double quote entries within the each and every fields.
    2) Column sequence for all the fields contains within the CSV file should to be maintained.
    3) Automatically 0 will be inserted into the database table when the District Number and Club IDs are blank in the csv file.


    The .CSV file has the form:

    District Number,City ID,City Name,Project Description.

    Any help would be greatly appreciated.

  • Re: Validate a CSV file with VB.NET

    01-23-2009, 7:20 AM
    Answer

    using a stream reader will allow you to read each file line and verify its integrity.

     

    I have create a working example with source code @ http://www.obilit.com/Examples/ReadCSV/

     

  • Re: Validate a CSV file with VB.NET

    01-27-2009, 5:15 AM

     Thanks for replying me soon.But what about the other two issues that i have mentioned in my queries:

    1) Needs to Validate the single quote and double quote entries within the each and every fields.

    3) Automatically 0 will be inserted into the database table when the District Number and Club IDs are blank in the csv file.

     I checked your source code but it cannot handle the above two cases.One think more, What will happen if my csv file contains value just like given below

    District Number:
    City ID:4356
    Address: Flat no: 10,Wing A,Mumbai
    City Name: lA
    Project Description:

    In the above case of "Address" column if we count the column header then it will remain same but the array value will increase due the extra comma that contains within the Address column.Now what you suggest for this ?.How to get ride of this glitch ?. Any Idea !

  • Re: Validate a CSV file with VB.NET

    01-27-2009, 5:28 AM
    • Star
      9,800 point Star
    • shashankgwl
    • Member since 09-19-2008, 3:18 PM
    • MUMBAI
    • Posts 1,937

    I created an excel file put up your data and saved it as a .csv file, then i opened the file using notepad and this is what i got

    district,city,address
    dist1,gwalior,"Flat no: 10, Wing A,Mumbai"

    dist2,mumbai,"woirwq,wioqruqw,iweriq"

     

    as you can  see that value that contain a ',' come in explicit double quotes i think this should solve your problem no. 2, same logic can be applied at problem no. 1

    SHASHANK BHIDE
    CAPGEMINI INDIA
    "THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT Wink "
  • Re: Validate a CSV file with VB.NET

    01-27-2009, 5:55 AM

     Hi Thanks, But what you have suggested already i know.Actually i want to validate the values of the CSV file before try to upload into the database.

    validation code should check Column sequence, single quote and double quote.here Column sequence means that ,suppose the column decrese in size than what is defined in database.How to handle thos eabove issue ? Could you suggest me.

  • Re: Validate a CSV file with VB.NET

    01-27-2009, 9:41 PM

    Ayan_Biswas_79:

     Hi all,

    I need to validate a csv file before it going to upload to a table.(Oracle Database)

    I need to validate the following:

    1) Needs to Validate the single quote and double quote entries within the each and every fields.
    2) Column sequence for all the fields contains within the CSV file should to be maintained.
    3) Automatically 0 will be inserted into the database table when the District Number and Club IDs are blank in the csv file.


    The .CSV file has the form:

    District Number,City ID,City Name,Project Description.

    Any help would be greatly appreciated.

    I think nvanhaaster@resultstel.com's idea is a good direction for your problem, you can read the file and save it in DataTable, then loop its column to validate its value. then insert it into database.

    Gary yang - MSFT
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Validate a CSV file with VB.NET

    01-28-2009, 2:18 AM
    Answer
    • Star
      11,863 point Star
    • shahed.kazi
    • Member since 07-08-2008, 10:15 PM
    • Sydney, Australia
    • Posts 2,330

     It is difficult to check for the quotes since you cannot know whether the quotes are part of the text itself or not.

  • Re: Validate a CSV file with VB.NET

    01-28-2009, 4:59 AM

     I have already checked his code but still i am unable to resolved the issue regarding teh double and single quotes contains in a particular column value

    Eg :

     4567,you can read the file " and save it in DataTable,5657

    You can see in the above text there is one double quote present, now my concern is how to handle this type of double quote and single quote.If double quote present in a value then it will be treated as 4 column while i have only three column.

     Thanks in advance

  • Re: Validate a CSV file with VB.NET

    03-26-2009, 7:53 AM

    Hi shashankgwl,

    Clould you kindly clarify my doubts mention below -

    When I open my csv file in notepad , I found that one of the value is within double quotes like -

    district,city,gwalior,"Flat no: 10, Wing A,Mumbai"

    But when i open that csv file in excel i didn't find any double quotes like

    district,city,gwalior,Flat no: 10, Wing A,Mumbai

    Please reply me .

    Thanks in advance.

  • Re: Validate a CSV file with VB.NET

    03-26-2009, 8:36 AM

    Hi shahed.kazi, 

    Clould you kindly clarify my doubts mention below -

    When I open my csv file in notepad , I found that one of the value is within double quotes like -

    district,city,gwalior,"Flat no: 10, Wing A,Mumbai"

    But when i open that csv file in excel i didn't find any double quotes like

    district,city,gwalior,Flat no: 10, Wing A,Mumbai

    Please reply me .

    Thanks in advance

Page 1 of 1 (10 items)