RE: copy datatable
From: Alex (Alex_at_discussions.microsoft.com)
Date: 03/21/05
- Next message: crino: "Re: lineSetEquipmentState and "No Service""
- Previous message: Peter Foot [MVP]: "Re: lineSetEquipmentState and "No Service""
- In reply to: Sitar: "copy datatable"
- Next in thread: Sitar: "RE: copy datatable"
- Reply: Sitar: "RE: copy datatable"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 21 Mar 2005 12:17:04 -0800
I don't know whether there would be any difference in performance but I often
use the following syntax (it's vb.net not c#)
Dim dtClone As DataTable
Try
dtClone = dtSource.Clone
For i = 0 To dtSource.Rows.Count - 1
dtClone.Rows.Add(dt.Rows(i).ItemArray)
Next
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
Try this and let me know if there's any perf differences, but in general
that's the way to go (wrap either what you're doing or what I'm doing into a
class and use its copy method). Much more convenient, I'm surprised msoft
didn't provide that method by default.
"Sitar" wrote:
> Hi,
>
> In my quest for performance, I come up with another question...
> There is no DataTable.Copy() with CF and I need to do that. So I came up
> with my own implementation which is as follow:
>
> public static DataTable DataTableCopy(DataTable dtOriginal)
> {
> DataTable dtCopy = dtOriginal.Clone();
> try
> {
> for (int j=0;j<dtOriginal.Rows.Count;j++)
> {
> dtCopy.ImportRow(dtOriginal.Rows[j]);
> }
> }
> catch(Exception ex)
> {
> throw new System.Exception("Datatable copy error", ex);
> }
>
> return dtCopy;
> }
>
> I'm wondering if it is the fastest way to do it though. I use ImportRow
> because I need to preserve the RowState values.
>
> Any comment on this?
>
> Thanks,
> Sitar.
>
- Next message: crino: "Re: lineSetEquipmentState and "No Service""
- Previous message: Peter Foot [MVP]: "Re: lineSetEquipmentState and "No Service""
- In reply to: Sitar: "copy datatable"
- Next in thread: Sitar: "RE: copy datatable"
- Reply: Sitar: "RE: copy datatable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|