Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

Table generic has a InsertAllOnSubmit[^] method, you can use to add multiple objects at one, like this:
C#
// dc = DataContext, assumes TableA contains items of type A
var toInsert = from b in TableB
               where ...
               select new A { ... };

TableA.InsertAllOnSubmit(toInsert);
dc.SubmitChanges();

or
C#
db
  .TableA
  .InsertAllOnSubmit(
    db
      .TableB
      .Where( ... )
      .Select(b => new A { ... })
  );

But even with deferred execution, every affected record will go all the way from the SQL server to the application and back. You better look for a server side solution. If the built-in tools are not enough, you can create .net integrated functions and procedures and add it to the server and database. This way, the data will not be serialized, will not travel, and you gain a lot of performance. If you decide to take this path, you can start here: http://msdn.microsoft.com/en-us/library/w2kae45k(v=vs.100).aspx[^]
 
Share this answer
 
v3
Comments
Mehdi Gholam 30-Jun-12 7:48am    
My 5!
Zoltán Zörgő 30-Jun-12 7:52am    
Thank you
Savalia Manoj M 2-Jul-12 2:31am    
Hi Zoltán Zörgő,Thanks for your answer But what about copy datatable to datatable. Because of i have not any DataContext here. i am working in datatable.
Zoltán Zörgő 2-Jul-12 11:19am    
You confuse things. You are using ADO.NET but you asked about LINQ. In LINQ to Sql you have DataContext instead of DataSet. You can force combining these approaches with System.Data.DataSetExtensions (see http://stackoverflow.com/questions/10855/linq-query-on-a-datatable), but it is an inelegant one, I think. In addition you force even more type conversion, boxing, and so on. You will even loose performance. Either way, if you need performance, try to solve this on server side.
Sandeep Mewara 30-Jun-12 12:36pm    
Good answer. My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900