I have the same names as xml in database, have tried with different dbtypes as int, float, nvarchar etc.
sometimes it copy only the first 2 elements in the xmldocument. I got an error that says "The given ColumnName 'omgang' does not match up with any column
in data source". And sometimes the "omgang" column is copied but with wrong value. I also tried with ColumnMappings without success.
Im using VS 2010 Express C# with Framework 2.0, SqlServer 2008 R2, SSMS.
http://netken.se/test/id=1&omgang=3484.xml
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using System.Data.SqlClient; namespace SqlBulkCopy1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connectionString = "Data Source=AK\\SQLEXPRESS;Initial Catalog=Test3;Integrated Security=True"; DataSet ds = new DataSet(); DataTable sourcedata = new DataTable(); ds.ReadXml(@"http://netken.se/test/id=1&omgang=3485.xml"); sourcedata = ds.Tables[0];
using (SqlConnection sqlconn = new SqlConnection(connectionString)) { sqlconn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlconn)) {
bulkCopy.DestinationTableName = "Tbl_Test3"; bulkCopy.WriteToServer(sourcedata); } } }
|