The .NET Framework 2.0 introduces a very handy new class in the System.Data.SqlClient namespace called SqlBulkCopy that makes it very easy and efficient to copy large amounts of data from your .NET applications to a SQL Server database. Transfering data from one source to another is a common practice in software development. This operation is preformed in many different scenarios which includes migration of the old system to the new system, backing up the data. VB.NET 2.0 includes the SqlBulkCopy class that helps to copy the data from different data sources to SQL SERVER database.
See my sample Query Result that copy the record set to other table with same database structure using class SQLBulkCopy.
Public Sub SqlCopyDataRow(ByVal SQLquery As String, ByVal dbConnection As String, _
ByVal TableName As String, ByVal ServerName As String, ByVal dbSchema As String)
Try
Dim otable As DataTable = clsDbConnection.ExecuteTable(dbConnection, CommandType.Text, SQLquery)
Dim reader As New DataTableReader(otable)
Dim sbc As SqlBulkCopy = New SqlBulkCopy("server=" & ServerName & "; database=" & _
dbSchema & ";Password=+xxxxxx+; User ID=sa")
sbc.DestinationTableName = TableName
sbc.WriteToServer(reader)
sbc.Close()
reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "S2xDE", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
using the procedure SqlCopyDataRow
SqlCopyDataRow("SELECT * FROM e1 WHERE ba_no = '" & gsBatchNo & "'", clsDbConnection.ConnProcess & _
"RES-1900", "co_e1", gsServerLocation, "RES-1900")
FREE PDF BOOK DOWNLOAD