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 |
eirikr_1
Starting Member
27 Posts |
Posted - 2013-02-21 : 16:52:45
|
i have exactly the same number in TempScan table as in scan.xls file.data is messing in columns. Please helphere is my code //Upload file to server in File folder and name Scans.xlsx UploadedFile file = txtFile.UploadedFiles[0]; string targetFolder = Server.MapPath("~/File"); file.SaveAs(Path.Combine(targetFolder, "scan.xlsx")); //Create ExcelData Adaptor and read to DataTable OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(); objDataAdapter.SelectCommand = ExcelConnection.GetConnection(Server.MapPath("~/File/scan.xlsx")); DataTable newScan = new DataTable(); objDataAdapter.Fill(newScan); objDataAdapter.Dispose(); // Create the SqlBulkCopy object. // Note that the column positions in the source DataTable // match the column positions in the destination table so // there is no need to map columns. using (SqlBulkCopy bulkCopy = new SqlBulkCopy(Conn)) { bulkCopy.DestinationTableName = "dbo.TempScan"; try { // Write from the source to the destination. bulkCopy.WriteToServer(newScan); } catch (Exception ex) { |
|
srimami
Posting Yak Master
160 Posts |
Posted - 2013-02-22 : 04:49:00
|
I haven't gone through your lengthy explanation but based on your subject line I can suggest that there might be some null values or empty values coming from source. In bulk insert, the preceding column will take this Null/empty value and might miss one column overall. Please check the source data, this might help as I encountered similar issue some time ago |
|
|
|
|
|