Skip to main content
spelling and code layout
Source Link
Gavin Miller
  • 44k
  • 22
  • 130
  • 191

SqlBulkCopy not wokringworking in VB.NET

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try
 

        End Using
 
    End Using

SqlBulkCopy not wokring in VB.NET

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try
 

        End Using
 
    End Using

SqlBulkCopy not working in VB.NET

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

Dim ds As New DataSet
Dim sourceData As New DataTable

'Populate Dataset with chosen XML
ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

'Gets the tables in the DataSet
sourceData = ds.Tables.Add

'Add the data
Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

    destinationConnection.Open()

    'Start copying!
    Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

        bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
        bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
        bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
        bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
        bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
        bulkCopy.DestinationTableName = "RISDCourseData"

        Try
            ' Write from the source to the destination.
            bulkCopy.WriteToServer(sourceData)

        Catch ex As Exception
            Response.Write(ex.Message)

        Finally
            ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
            ' at the end of the Using block.
            bulkCopy.Close()
            'Response.Redirect("Default.aspx")
        End Try

    End Using
End Using
removed some extraneous comments
Source Link
mmcglynn
  • 7.7k
  • 18
  • 54
  • 83

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    'Get connection string from web.config
    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    '(ConfigurationManager.ConnectionStrings("Foo_ContentConnectionString").ConnectionString)

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try


        End Using

    End Using

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    'Get connection string from web.config
    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    '(ConfigurationManager.ConnectionStrings("Foo_ContentConnectionString").ConnectionString)

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try


        End Using

    End Using

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try


        End Using

    End Using
Source Link
mmcglynn
  • 7.7k
  • 18
  • 54
  • 83

SqlBulkCopy not wokring in VB.NET

This code giving me fits. Returns the error:

The given ColumnName 'COURSENAME' does not match up with any column in data source.

If I remove the mappings, nothing gets written to the db either. Help!

    'Get connection string from web.config
    Dim connectionString As String = "Data Source=2UA72518QY\SQLEXPRESS;Integrated Security=True;Pooling=False;Initial Catalog='Foo_Content'"

    '(ConfigurationManager.ConnectionStrings("Foo_ContentConnectionString").ConnectionString)

    Dim ds As New DataSet
    Dim sourceData As New DataTable

    'Populate Dataset with chosen XML
    ds.ReadXml(Server.MapPath("xml/FOOSECTIONS.XML"))

    'Gets the tables in the DataSet
    sourceData = ds.Tables.Add

    'Add the data
    Using destinationConnection As SqlConnection = New SqlConnection(connectionString)

        destinationConnection.Open()

        'Start copying!
        Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)

            bulkCopy.ColumnMappings.Add("COURSENAME", "COURSENAME")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSETITLE")
            bulkCopy.ColumnMappings.Add("COURSEDESC", "COURSEDESC")
            bulkCopy.ColumnMappings.Add("COURSETITLE", "COURSEFACULTY")
            bulkCopy.ColumnMappings.Add("COURSETERM", "COURSETERM")
            bulkCopy.DestinationTableName = "RISDCourseData"

            Try
                ' Write from the source to the destination.
                bulkCopy.WriteToServer(sourceData)

            Catch ex As Exception
                Response.Write(ex.Message)

            Finally
                ' Close the SqlDataReader. The SqlBulkCopy object is automatically closed
                ' at the end of the Using block.
                bulkCopy.Close()
                'Response.Redirect("Default.aspx")
            End Try


        End Using

    End Using