Forums » .NET » .NET »

Copy one Datatable to another datatable.


Posted Date: 30 Jun 2012      Posted By:: Manoj Savalia     Member Level: Silver    Member Rank: 776     Points: 5   Responses: 3



Hi,
I have one datatable which contain Employee Information like
EmpID,EmpName,EmpAdd etc...
In my datatable EmpName and EmpAdd is Encrypted. So when i bind it to grid that time i want to convert it to string.
for Ex.


DataTable dt = new DataTable();
foreach (DataRow item in dsReturn.Tables[0].Rows)
{
DataRow dr = dt.NewRow();
dr["EmpID"] = item["EmpID"];
dr["EmpName"] = ConverterByteToString((byte[])item["EmpName"]);
dr["EmpAdd"] = ConverterByteToString((byte[])item["EmpAdd"]);
dt.Rows.Add(dr);
}

Is there any way to copy all row into new table using Linq?

This work fine but when large amount of data procedure that time it's slow. So i want to simplify it.





Responses

#678285    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 01/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Manoj,

There is easy simple method is available to copy data from one to another like below code refer below code sample


//for example already you got data in the dt table copy that data to dtcpy dattable using below code
DataTable dtcpy = new DataTable();
dtcpy = dt;
//Another way
dtcpy = dt.Copy();


Regards
N.Ravindran
Your Hard work never fails



 
#678286    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 01/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,



If dt1 is datatable with some data...
dt2 is other datatable.

Datatable dt2;
dt2=dt1.copy();


If you want to copy only the structure without data same as dt1


dt2=dt1.Clone();

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too



 
#678319    Author: Manoj Savalia      Member Level: Silver      Member Rank: 776     Date: 01/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Thanks SonyMadhu,
But i want to change some columns value when add to new datatable like,

dr["EmpName"] = ConverterByteToString((byte[])item["EmpName"]);
dr["EmpAdd"] = ConverterByteToString((byte[])item["EmpAdd"]);

How it can be possible??






 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Browse excel file and create XML map for each column
Previous : Calling C# Code file's Functions From Crystal report
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.