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. C#
  4. Tab Delimited file to sql database

Tab Delimited file to sql database

Scheduled Pinned Locked Moved C#
databasehelpsql-serversysadmintutorial
3 Posts 2 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.
  • G Offline
    G Offline
    gavindon
    wrote on last edited by
    #1

    ok, I have most of this worked out, but do have one problem. I have a tab delimited text file that I am reading out into a datatable in the code, then pushing that to a stored proc on sql server. That part works but here is the problem. This file has 15 columns in it. The following code is putting EACH line into the datatable 15 times.....

    using (StreamReader file = new StreamReader(@"C:\ProductionLog.txt"))
    {
    while ((line = file.ReadLine()) != null)
    {

                    char\[\] delimiters = new char\[\] { '\\t' };
                    string\[\] rows = line.Split(delimiters, StringSplitOptions.None);
                   
                    for (int i = 0; i < rows.Length; i++)
                    {
                        dt.Rows.Add(rows);
                    }//end for
                 }//end while
                 file.Close();
            }//end using streamreader
    

    so I am getting,

    BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
    BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
    BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0

    15 times( it will do line 2 after it does the 15 and does it 15 times as well), instead of

    BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
    BUNDLE 01/29/13 01:43 pm 7 5" 7' 64 5 84 1 6 16.96 54.262 9 1 2
    BUNDLE 01/29/13 01:44 pm 7 5" 7' 65 5 84 1 6 17.56 33.712 15 4 0

    and so on. Can somebody tell me how much of a dumn** I am being and how to fix this?

    Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

    M 1 Reply Last reply
    0
    • G gavindon

      ok, I have most of this worked out, but do have one problem. I have a tab delimited text file that I am reading out into a datatable in the code, then pushing that to a stored proc on sql server. That part works but here is the problem. This file has 15 columns in it. The following code is putting EACH line into the datatable 15 times.....

      using (StreamReader file = new StreamReader(@"C:\ProductionLog.txt"))
      {
      while ((line = file.ReadLine()) != null)
      {

                      char\[\] delimiters = new char\[\] { '\\t' };
                      string\[\] rows = line.Split(delimiters, StringSplitOptions.None);
                     
                      for (int i = 0; i < rows.Length; i++)
                      {
                          dt.Rows.Add(rows);
                      }//end for
                   }//end while
                   file.Close();
              }//end using streamreader
      

      so I am getting,

      BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
      BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
      BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0

      15 times( it will do line 2 after it does the 15 and does it 15 times as well), instead of

      BUNDLE 01/29/13 01:42 pm 7 5" 7' 63 5 84 1 6 17.31 31.155 16 0 0
      BUNDLE 01/29/13 01:43 pm 7 5" 7' 64 5 84 1 6 16.96 54.262 9 1 2
      BUNDLE 01/29/13 01:44 pm 7 5" 7' 65 5 84 1 6 17.56 33.712 15 4 0

      and so on. Can somebody tell me how much of a dumn** I am being and how to fix this?

      Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

      M Offline
      M Offline
      Matt T Heffron
      wrote on last edited by
      #2

      Don't you just want:

      // for (int i = 0; i < rows.Length; i++)
      // {
      dt.Rows.Add(rows); // only insert it once
      // }//end for

      G 1 Reply Last reply
      0
      • M Matt T Heffron

        Don't you just want:

        // for (int i = 0; i < rows.Length; i++)
        // {
        dt.Rows.Add(rows); // only insert it once
        // }//end for

        G Offline
        G Offline
        gavindon
        wrote on last edited by
        #3

        :doh: :doh: :doh: :doh: :doh: You sir are a genius( or I am a dumb***, take your pick :-D ) I knew I was doing something stupid, I just couldn't see it.

        Treat stressful situations like a dog, if you can't eat it, play with it or screw it, then just piss on it and walk away. Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow.

        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