1
このコードは私に合っています。VB.NETでSqlBulkCopyが動作しない
The given ColumnName 'COURSENAME' does not match up with any column in data source.
マッピングを削除すると、何もDBに書き込まれません。助けて! ds.Tables.Add
を使用することにより
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
ブリリアント!ありがとうございました! – mmcglynn