Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2006, 12:57 PM
Authorized User
 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default sqlBulkCopy problem

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" />&nbsp;
        <br />
        <br />
        <asp:Label ID="lblResult" Runat="server"></asp:Label>
        <br />
        <br />
        <asp:Label ID="lblCounter" Runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>







Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlBulkCopy Help cangerer .NET Framework 2.0 0 March 23rd, 2006 10:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.