Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
andrewcw
Posting Yak Master
133 Posts |
Posted - 2012-06-01 : 19:27:16
|
| I have a very simple table of 5 fields ( no indexes or keys ). I am running a simple test by taking the first 20 records into a datatable and then adding some 300 more rows.I can see the new rows in the datatable. The code below generates no errors - but does not update the table. If I create a datatable of just the changes, it raises an error it cannot access the table. That sounds weird. Columns are not mapped because they are the same. I have traced the code to the function WriteToServer. What could be wrong ? public string copyBulkData(DataTable sourceTable, string TargetSQLTableName) { string errormes = string.Empty; if (staticSQLConn.State == ConnectionState.Closed) { staticSQLConn.Open(); } try { SqlBulkCopy s = new SqlBulkCopy(staticSQLConn); DataTable changesOnly = sourceTable.GetChanges(); s.DestinationTableName = TargetSQLTableName; // s.WriteToServer(changesOnly); // raises error cannot access the table... s.WriteToServer(sourceTable, DataRowState.Modified); } catch (Exception e) { errormes = e.Message; SQLDataLayerError = errormes; } return errormes; }Thanks !andrewcw |
|
|
|
|
|