<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Copy values of one row to another row</Title>
      <Shortcut>Copyvaluesofonerowtoanotherrow</Shortcut>
      <Description>Copy values of one row to another row [VB.NET]</Description>
      <Author>Dwaine Wright</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=49c1e719-bcaa-4f65-8002-69cf9df6231b</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="VB"><![CDATA[Shared Function CopyRowValues(ByVal SourceRow As DataRow, ByVal TargetRow As DataRow) As Integer
        Dim SR As DataRow = SourceRow
        Dim TR As DataRow = TargetRow
        Dim ST As DataTable = SR.Table
        Dim TT As DataTable = TR.Table
        Dim SC As DataColumn
        Dim TC As DataColumn
        Dim Copied As Integer
        For Each SC In ST.Columns
            TC = TT.Columns(SC.ColumnName)
            If Not TC Is Nothing AndAlso Not TC.ReadOnly Then
                If TC.DataType.GetType Is SC.DataType.GetType Then
                    Try
                        TR(TC) = SR(SC)
                        Copied += 1
                    Catch oEx As Exception
                    End Try
                End If
            End If
        Next
        Return Copied
    End Function]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>