RE: copy datatable

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Alex (Alex_at_discussions.microsoft.com)
Date: 03/21/05


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



Relevant Pages

  • RE: copy datatable
    ... use the following syntax ... Dim dtClone As DataTable ... "Sitar" wrote: ... > In my quest for performance, I come up with another question... ...
    (microsoft.public.dotnet.framework.performance)
  • Re: copy datatable
    ... > Sitar. ... >> use the following syntax ... >> Dim dtClone As DataTable ... >> Try this and let me know if there's any perf differences, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: copy datatable
    ... > Sitar. ... >> use the following syntax ... >> Dim dtClone As DataTable ... >> Try this and let me know if there's any perf differences, ...
    (microsoft.public.dotnet.framework.performance)