Tab Delimited file to sql database
-
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 015 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 0and 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.
-
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 015 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 0and 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.
Don't you just want:
// for (int i = 0; i < rows.Length; i++)
// {
dt.Rows.Add(rows); // only insert it once
// }//end for -
Don't you just want:
// for (int i = 0; i < rows.Length; i++)
// {
dt.Rows.Add(rows); // only insert it once
// }//end for: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.