transferring parsed data to local table with columns from local raw data table with only one...

  • Thread starter Thread starter Rich P123
  • Start date Start date
R

Rich P123

Guest
I want to know if there is a way I can forgo a bunch of for loops for transferring parsed data to a local table in my project that contains multiple columns from a local raw data table -- kind of like performing the data transfer in a bulk insert fashion. For example, I have to read in data from a text file. The fields are not really delimited. They are separated by blank spaces. Some fields may be separated by one space while other fields are separated with multiple spaces.

"aaa bbb ccc ddd eee fff"

I read the data from the text file using ADO.Net with OleDB -- no loops, no streamReader, its kind of like a bulk insert

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\folder1; Extended Properties=text;HDR=No;FMT=Delimited(\t);");

OleDbCommand cmd = new OleDbCommand(string.Format("SELECT * FROM [{0}]", "dv.txt"), con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dataset1, "tbl1");

Then I actually do massage the data a little bit because I dont want all the rows. I use a linq query to transfer only the desired rows to another local data table:

var tbl2 = new DataTable();
tbl2.Columns.Add("G1");
tbl2 = (from a in dataset1.Tables["tbl1"].AsEnumerable()
where a.Field<string>("F1").StartsWith("USGS")
select a).CopyToDataTable();

finally, I parse each row using Regex to capture any blank spaces

string str1 = tbl2.Rows[0].ToString();
string[] arr1 = Regex.Split(str1, @"\s+");

This is the part where I am having to loop through tbl2 to get each row and then say I have tbl3 with 6 columns to receive the parse data. I would have to loop through my parsed array for each row -- there are thousands of rows. Im just checking if there is a way I could forgo all this looping for my given scenario, or is looping the only way to do this? Or maybe there is a better approach altogether? Maybe I want to do this with lists<T> ?

Any suggestions appreciated.








Rich P

Continue reading...
 
Back
Top