You can use
SqlBulkCopy
method, here is the C# code
using (SqlConnection connSource = new SqlConnection(connectionstring))
using (SqlCommand cmd = connSource.CreateCommand())
using (SqlBulkCopy bcp = new SqlBulkCopy(connectionstring))
{
bcp.DestinationTableName = "table1";
cmd.CommandText = "SELECT Fld1, Fld2 FROM ##TmpTable";
cmd.CommandType = CommandType.Text;
connSource.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
bcp.WriteToServer(reader);
}
}
VB.net converted code, i'm not VB.net developer, please get only the idea and proceed.
Using connSource As New SqlConnection(connectionstring)
Using cmd As SqlCommand = connSource.CreateCommand()
Using bcp As New SqlBulkCopy(connectionstring)
bcp.DestinationTableName = "table1"
cmd.CommandText = "SELECT Fld1, Fld2 FROM ##TmpTable"
cmd.CommandType = CommandType.Text
connSource.Open()
Using reader As SqlDataReader = cmd.ExecuteReader()
bcp.WriteToServer(reader)
End Using
End Using
End Using
End Using