DataTable to DataTable

  • Thread starter Thread starter ArunDhaJ
  • Start date Start date
A

ArunDhaJ

Hi All,
I'm having a DataTable with say 3 columns. I've to copy this DataTable
to another DataTable which has 4 columns. The extra column is the
Row_ID with AutoIncrement property set true.

Is this way is possible?

Anyways, what I actually need is to add a new column Row_ID with
AutoIncrement values.

Source Table
EName EDesignation
Abc Engineer
Bcd Sr.Engineer

Destination Table should be like this
Row_ID EName EDesignation
1 Abc Engineer
2 Bcd Sr.Engineer

Thats it,

Thanks in Advance
ArunDhaJ
 
Hi All,
I'm having a DataTable with say 3 columns. I've to copy this DataTable
to another DataTable which has 4 columns. The extra column is the
Row_ID with AutoIncrement property set true.

Is this way is possible?


Of course, just do a loop in the first table rows and add a new row to
the second one.
 
Is there any way other than looping? As the DataTable would contain
more than 20K records, in that case this would easily infects the
performance.

Thanks
ArunDhaJ
 
Is there any way other than looping? As the DataTable would contain
more than 20K records, in that case this would easily infects the
performance.

Since DataTable is an in-memory structure, and is, in fact, just a
glorified List<DataRow> with optional indexing and constraint
checking, there isn't a more efficient way to do what you want (just
as there wouldn't be with plain List<T>).
 
Is there any way other than looping? As the DataTable would contain
more than 20K records, in that case this would easily infects the
performance.

Thanks
ArunDhaJ


Well, anything with 20K rows in memory will have an impact !!!

Besides, think about it, even if YOU do not do the loop, somebody else
would have to do it :). There is no way to avoid the loop

I think you better use a DB, cause 40k rows (20k*2 tables) are a lot
to be hold in memory
 
Ya. That was the final option which I had. And now proceeding in that
way. :-)
Thanks for your guidance..

Regards
ArunDhaJ
 
I think you better use a DB, cause 40k rows (20k*2 tables) are a lot
to be hold in memory

Not really - at 1k per row (which is probably an overestimate), it's
still only 40Mb, which isn't all that much. In fact, if you use SQL
Server with a database of that size, it will likely also load the data
entirely into memory to speed up queries.

Of course, a proper database is still preferrable as soon as you start
to do queries which are more complicated than "WHERE Name = 'John'".
 

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

Back
Top