Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 missing column when doing sqlbulkcopy
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

27 Posts

Posted - 02/21/2013 :  16:52:45  Show Profile  Reply with Quote
i have exactly the same number in TempScan table as in scan.xls file.
data is messing in columns. Please help

here 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();

// 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";

// Write from the source to the destination.
catch (Exception ex)

Posting Yak Master

160 Posts

Posted - 02/22/2013 :  04:49:00  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000