vb.net CSV import into sql express 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kentsway
    New Member
    • Jul 2007
    • 1

    vb.net CSV import into sql express 2005

    I'm a newbie.

    I'm writing my first VB.net program. Our company gets a weekly csv file from the head office that contains a list of all employees and their contact information.

    Im trying to write an application that can be used by our branch office that will automatically import the csv file into SQL express 2005.

    Using this site and others I've figured out how to import the csv file (Employees.csv) into a dataset and how to use sqlBulkCopy to write the data to the employee table in the sql 2005 database. But this leaves me with 2 problems that I'm totally stuck on.

    1. If an employee record already exists in the sql database then the sqlBulkcopy stops inserting and causes an error, the employee ID is the promary key in the sql db.

    2. I also need to update any existing employee record in the sql db to the data that is in the csv file.

    So... I'm trying to come up with a method to fix both of these problems. If anyone has a solution please provide some sample code for it as I'm very new on everthing.

    TIA
  • jai80
    New Member
    • Nov 2006
    • 30

    #2
    Originally posted by Kentsway
    I'm a newbie.

    I'm writing my first VB.net program. Our company gets a weekly csv file from the head office that contains a list of all employees and their contact information.

    Im trying to write an application that can be used by our branch office that will automatically import the csv file into SQL express 2005.

    Using this site and others I've figured out how to import the csv file (Employees.csv) into a dataset and how to use sqlBulkCopy to write the data to the employee table in the sql 2005 database. But this leaves me with 2 problems that I'm totally stuck on.

    1. If an employee record already exists in the sql database then the sqlBulkcopy stops inserting and causes an error, the employee ID is the promary key in the sql db.

    2. I also need to update any existing employee record in the sql db to the data that is in the csv file.

    So... I'm trying to come up with a method to fix both of these problems. If anyone has a solution please provide some sample code for it as I'm very new on everthing.

    TIA
    Hi,

    I am working in CSV file using asp.net. I came across the following problem and am stuck with it. can u assist me coz u have worked in the same grnd.

    this is the sample batch of records that i have in my csv file,

    1,'KS010','S',0 9,345
    2,'KS011','S',0 9,346
    3,'KS012','S',0 9,347
    4,'KS013','S',0 9,348
    01,'AS010','S', 09,345
    02,'AS011','S', 09,346
    07,'AS012','S', 09,347
    08,'AS013','S', 09,348
    ............... .............
    ............... ...

    while trying to retrieve the above batch of records from the CSV file using the dataset and to write the data to my sql table, i endup getting the records in the below pattern...

    1,'10','S',09,3 45
    2,'11','S',09,3 46
    3,'12','S',09,3 47
    4,'13','S',09,3 48
    01,'AS010','S', 09,345
    02,'AS011','S', 09,346
    07,'AS012','S', 09,347
    08,'AS013','S', 09,348

    the code value that started with KS0.., gets truncated and i get only 10,11,12,13; whereas for the next set of records that has the code starting with AS0..,it is returned without any truncation. i am able to get the full code value,that you can see from the above set of records. would be of great help if u assist me with some solution. Thanks in advance. hope i've provided a clear description of the problem am facing.

    cheers,
    jai

    Comment

    • ewsteiner
      New Member
      • Aug 2007
      • 1

      #3
      Originally posted by Kentsway
      I'm a newbie.

      I'm writing my first VB.net program. Our company gets a weekly csv file from the head office that contains a list of all employees and their contact information.

      Im trying to write an application that can be used by our branch office that will automatically import the csv file into SQL express 2005.

      Using this site and others I've figured out how to import the csv file (Employees.csv) into a dataset and how to use sqlBulkCopy to write the data to the employee table in the sql 2005 database. But this leaves me with 2 problems that I'm totally stuck on.

      1. If an employee record already exists in the sql database then the sqlBulkcopy stops inserting and causes an error, the employee ID is the promary key in the sql db.

      2. I also need to update any existing employee record in the sql db to the data that is in the csv file.

      So... I'm trying to come up with a method to fix both of these problems. If anyone has a solution please provide some sample code for it as I'm very new on everthing.

      TIA
      I am trying to write a similar program but can not get it to connect to my SQL server. Can you please post your code?

      Comment

      Working...