SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

eirikr_1
Starting Member

26 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();
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 - 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  
 New 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.04 seconds. Powered By: Snitz Forums 2000