Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

CSV Import

I am importing a csv file into my Database. It is a comma delimitered file.
I have 2 tables

tPhonebook  - ID, sBook
tContacts  -  ID, sName, sPhone, iPhonebookID

iPhonebookID is linked to ID of tPhonebook

The csv file consists of

Column 1 - Name
Column 2 - Number

Column 3, 4, 5 etc is the name of a Phonebook.

I need the import to add a phone book for every column named after column 2, it could be one or multiple columns, it is different for every row.

I then need it to add that contact to each phone book and move to the next row.

If the phone book exists already I just need to ID for iPhonebookID.
0
mgordon-spi
Asked:
mgordon-spi
1 Solution
 
Habib PourfardSoftware DeveloperCommented:
Would you please give us a sample record of the csv file. is it like this?

Name, Number, Col1, Col2, Col3
--------------------------------------
John, 123456, Phonebook1, NULL, NULL
John, 123456, NULL, Phonebook2, NULL
0
 
Kalpesh ChhatralaSoftware ConsultantCommented:
Hi,
try below CSV Import Sample

http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader

hth

Kalpesh
0
 
mgordon-spiAuthor Commented:
The csv would be like this

John, 123456, Phonebook1,  
John, 123456, Phonebook1, Phonebook2, Phonebook3,
John, 123456, Phonebook1, Phonebook2,

if there is only one phone book there is only 3 columns if there is 2 phone books there is 4 columns and so on. There would never be a null column and then a phone book column
0
 
CodeCruiserCommented:
That's not a properly formatted CSV file so you would need to read the file line by line, break the line on comma and then deal with the outcome manually

ForEach Line As String In IO.File.ReadAllLines("path")
      Dim words As String() = Line.Split(",")
      For each word As String in words
            'code here
      Next
Next
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now