Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Import CSV file to MS Access

Import CSV file to MS Access

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasedata-structureshelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scothykonma
    wrote on last edited by
    #1

    Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...

    E M 2 Replies Last reply
    0
    • S scothykonma

      Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...

      E Offline
      E Offline
      emimmortal
      wrote on last edited by
      #2

      You can open the mdb with any .net connection and use the INSERT SQL to import the csv data. Ensure the target table is blank and make a Schema.ini file for define the schema of the csv file. eg. string sql = string.Format("insert into {0} select * from [Text;FMT=Delimited(|);HDR=No;DATABASE={1};].[{2}#csv];", info.TableName, info.FilePath, info.FileName); System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(sql, connection); command.ExecuteNonQuery(); for schema.ini http://msdn.microsoft.com/en-us/library/ms709353.aspx :)

      Emimmortal

      S 1 Reply Last reply
      0
      • S scothykonma

        Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        When you create this post it suggested you first search the site and ot Google. This is one of the most asked questions ANYWHERE, do the searches!

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • E emimmortal

          You can open the mdb with any .net connection and use the INSERT SQL to import the csv data. Ensure the target table is blank and make a Schema.ini file for define the schema of the csv file. eg. string sql = string.Format("insert into {0} select * from [Text;FMT=Delimited(|);HDR=No;DATABASE={1};].[{2}#csv];", info.TableName, info.FilePath, info.FileName); System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(sql, connection); command.ExecuteNonQuery(); for schema.ini http://msdn.microsoft.com/en-us/library/ms709353.aspx :)

          Emimmortal

          S Offline
          S Offline
          scothykonma
          wrote on last edited by
          #4

          Thanks for your reply.... My target table contains values(master table).I want to add the selected columns( appropriate values) from the csv file to related fields in the master table..(Mapping via field names, if csv doesn't contain field names we can assign...) How is this possible... Please explain...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups