code in c# to read data from csv file and put in sql server 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikaspillai82
    New Member
    • Jul 2007
    • 2

    code in c# to read data from csv file and put in sql server 2005

    I have a csv file and it contains 4 columns which contain ip address of world.
    example :
    the colms are :
    starting ip, endip, country code and country name ,
    starting ip contains ip address like 200.1.3.4 same in end ip also

    now the coloums in sql are
    id , startip_1, startip_2...... .startip_6 , endip_1, endip_2.....end ip_6, country code, country name .

    now i want to select the 1 by 1 row from csv file and store data in sql , something like 200.1.2.3 should be send to sql like 200 to startip_1, 1to startip_2...... . and so ....hope u r getting what i want .

    I am new to C# .. please give me the code and help me by providing solution step by step ..i m using sql server 2005 and C# 2005

    startip_5, startip_6 and endip_5 and end_6 r null in sql rest all r not null .

    please if anyone can give me solution to this on today itself ... it urgent...

    thnk you.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Data Transformation Services (DTS) allows you to import and export data from and to data sources (such as Microsoft Excel) that use an OLE DB provider. DTS replaces the Access import and export functions and also provides functions to: Export and import data to and from another SQL Server; export and import data to and from various formats such as Excel (XLS), Comma-Separated Values (CSV), and Microsoft Access; and, perform transformations on data. HTH.

    Comment

    • RoninZA
      New Member
      • Jul 2007
      • 78

      #3
      Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

      82, what I would suggest is to open your file using a System.IO.Strea mReader, with reference to the path of your file. Use the StreamReader.Re adLine method to read a line from your file into a string, and parse the string using the string.Split('' ) method, to break it up into the data sections you need.

      These can then be easily inserted into a SQL table.

      Hope it helps!

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        DTS is a free download addon.
        But yes, if you want to do in-application transfer then reading in the file and parsing it would be correct.

        Originally posted by RoninZA
        Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

        82, what I would suggest is to open your file using a System.IO.Strea mReader, with reference to the path of your file. Use the StreamReader.Re adLine method to read a line from your file into a string, and parse the string using the string.Split('' ) method, to break it up into the data sections you need.

        These can then be easily inserted into a SQL table.

        Hope it helps!

        Comment

        • vikaspillai82
          New Member
          • Jul 2007
          • 2

          #5
          [QUOTE=RoninZA]Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

          82, what I would suggest is to open your file using a System.IO.Strea mReader, with reference to the path of your file. Use the StreamReader.Re adLine method to read a line from your file into a string, and parse the string using the string.Split('' ) method, to break it up into the data sections you need.

          These can then be easily inserted into a SQL table.

          Hope it helps![/QUOfghTE]

          sdfsgdgdgdgdgdg dgdgdgdgdgdgdgd gd

          Comment

          Working...