Hi
I should start off by saying I'm by no means a programming guru - if my post seems a bit amateurish...apologies.
I tried a modified version of the code in Chapter 12 (example 12-5) but nothing happens when I press the 'Start Bulk Copy' button all I get is
"The given ColumnMapping does not match up with any column in the source or destination. "
Even though I'm simply copying between two tables based on the same column format.
When I've tried other stripped down examples all that happens is the button is pressed, page re-loads but nothing has actually been executed. The event log has nothing.
Below is my original code - any help or suggestions would be much appreciated
<%@ Page Language="
VB" debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
Sub btnBulkCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBulkCopy.Click
Dim BooksConString As String
Dim NorthWindConString As String
Dim BooksCon As SqlConnection = New SqlConnection()
Dim NorthwindCon As SqlConnection = New SqlConnection()
Dim BooksCom As SqlCommand = New SqlCommand()
Dim BooksReader As SqlDataReader
BooksConString = "Data Source=localhost;Initial Catalog=Books;Persist Security Info=True;User ID=sa;Password="
NorthWindConString = "Data Source=localhost;Initial Catalog=Books;Persist Security Info=True;User ID=sa;Password="
BooksCon.ConnectionString = BooksConString
BooksCom.Connection = BooksCon
BooksCom.CommandText = " select * from northwind.dbo.customers"
BooksCom.CommandType = CommandType.Text
BooksCom.Connection.Open()
Dim NorthWindBulkOp As SqlBulkCopy
NorthWindBulkOp = New SqlBulkCopy(NorthWindConString,SqlBulkCopyOptions. UseInternalTransaction)
NorthWindBulkOp.DestinationTableName = "Customer2"
NorthWindBulkOp.ColumnMappings.Add("CustomerID","C ustomerID")
NorthWindBulkOp.ColumnMappings.Add("CompanyName"," CompanyName")
NorthWindBulkOp.ColumnMappings.Add("ContactName"," ContactName")
NorthWindBulkOp.ColumnMappings.Add("ContactTitle", "ContactTitle")
NorthWindBulkOp.ColumnMappings.Add("Address","Addr ess")
NorthWindBulkOp.ColumnMappings.Add("City","City")
NorthWindBulkOp.ColumnMappings.Add("Region","Regio n")
NorthWindBulkOp.ColumnMappings.Add("PostalCode","P ostalCode")
NorthWindBulkOp.ColumnMappings.Add("Country","Coun try")
NorthWindBulkOp.ColumnMappings.Add("Phone","Phone" )
NorthWindBulkOp.ColumnMappings.Add("Fax","Fax")
Dim CustomerTitleColMap As SqlBulkCopyColumnMapping
CustomerTitleColMap = New SqlBulkCopyColumnMapping("CompanyName","Source")
NorthWindBulkOp.ColumnMappings.Add(CustomerTitleCo lMap)
NorthWindBulkOp.BulkCopyTimeout = 500000000
AddHandler NorthWindBulkOp.SqlRowsCopied, _
New SqlRowsCopiedEventHandler(AddressOf OnSqlRowsCopied)
NorthWindBulkOp.NotifyAfter = 1000
BooksReader = BooksCom.ExecuteReader()
Try
NorthWindBulkOp.WriteToServer(BooksReader)
Catch ex As Exception
' Write error handling code here
lblResult.Text = ex.Message
Finally
BooksReader.Close()
End Try
End Sub
Private Sub OnSqlRowsCopied(ByVal sender As Object, _
ByVal args As SqlRowsCopiedEventArgs)
lblCounter.Text += args.RowsCopied.ToString() + " rows are copied<Br>"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Bulk Loading Large Volume Data</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnBulkCopy" Runat="server" Text="Start Bulk Copy" />
<br />
<br />
<asp:Label ID="lblResult" Runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lblCounter" Runat="server"></asp:Label>
</div>
</form>
</body>
</html>