Mapping Columns w/o DataAdapter?

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?
 
W

William \(Bill\) Vaughn

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.
__________________________________
 
B

Bostonasian

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.
 
C

CodeMeister

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
 
R

Rogas69

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top