Mapping Columns w/o DataAdapter?

  • Thread starter Thread starter Bostonasian
  • Start date Start date
B

Bostonasian

The title may not reflect what I exactly want to acheive, but what I
want to do ultimately is to map columns between 2 data tables. One
already has data and the other has schema but no data. And I want to
transfer the data to the empty one(Of course, those two datatable has
different column names).

I see many example of table/column mapping with data that were
extracted from database, then immedietely do mapping and add table
mapping object to DataAdapter.

But in my case, I already have source data ready, therefore I don't
need to use DataAdapter to retrieve data from database.

Can anyone help?
 
Okay, what's the problem you're trying to solve with moving data from one DA
to another?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Yes. Actually,I kinda figured it out.
I did something like this.

I've got 3 data tables.

1. DataTable contains original source.

2. DataTable contains mapped columns between src and destination.
ex.
Src |Dest
--------------
fName|first_name
lName|last_name
email|email_address

3. Destination DataTable

And I did something like this:

foreach(DataRow srcDr in SrcDataTable.Rows){
DataRow newRow = destDataTable.NewRow();

foreach(DataRow mpCol in ColMapDataTable.Rows){
string _srcColName = (string) mpCol["Src"];
string _dstColName = (string) mpCol["Dest"];
newRow[_dstColName] = mpCol[_srcColName]
}
destDataTable.Rows.Add(newRow);
}

This works fine. If anyone know better way, let me know.
 
How about something like this?

DataTable destTable = srcTable.Copy();
DataColumnCollection cols = destTable.Columns;
foreach(DataRow mpCol in ColMapDataTable.Rows)
{
cols[(string) mpCol["Src"]].ColumnName = (string)
mpCol["Dest"];
}


IHTH

Jon
 
What db engine is this? i believe that it might be faster to execute query
that would transfer data on the server side and then retrieve data for the
second table if you need them.

Peter
 
Back
Top