Try this to copy one dataset to another.
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim dsOriginal As Data.DataSet
Dim dsCopy As Data.DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub CopyTable()
Dim iCounter As Integer = 0
Dim myTable As DataTable
Dim myRow As DataRow
Dim myColumn As DataColumn
Dim blanktable As DataTable = New DataTable
'This will create the columns in the new datatable identical to the existing dataset table
For Each myColumn In dsOriginal.Tables(0).Columns
blanktable.Columns.Add(myColumn.ColumnName.ToString)
Next
'add the new table to the blank dataset.
dsCopy.Tables.Add(blanktable)
For Each myRow In dsOriginal.Tables(0).Rows
Dim drv As DataRow = dsCopy.Tables(0).NewRow
For Each myColumn In dsOriginal.Tables(0).Columns
'copy the contents of the original table to the copy
drv(myColumn.ColumnName) = myRow(myColumn.ColumnName)
Next myColumn
dsCopy.Tables(0).Rows.InsertAt(drv, iCounter) 'insert the copied row into the table
iCounter += 1
Next myRow
' then do what ever you want with the dataset like bind it to a new grid
End Sub
End Class
hope this helps. check out my siganture line there is a valuable resource for .Net Programming and its cheap too!
George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!