0

i use SqlBulkCopy to insert data from OleDbDataReader (contains data from xls) to mssql-2005 i have a cloumn on the OleDbDataReader that contains number stored as text (in the xls)

when i look into the mssql data i see null in that column all other columns are move ok.

link text

Muhammad Akhtar
52.2k37 gold badges143 silver badges191 bronze badges
asked Dec 1, 2009 at 11:29

2 Answers 2

3

you need to map columns like in the code...

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destConnection))
 {
 bulkCopy.ColumnMappings.Add("ID", "ID");
 bulkCopy.ColumnMappings.Add("Email", "Email");
 bulkCopy.DestinationTableName = "tableName";
 bulkCopy.WriteToServer(ExcelReader);
 }
answered Dec 1, 2009 at 11:49
Sign up to request clarification or add additional context in comments.

Comments

1

When one bulk copies from SQL server to SQL Server, the source is able to indicate very well the data types to the destination. With Excel, the source makes guesses about the data type. You may have the Excel formatted as text, but the source (ODBC?) might look at the first 50 rows and guess that it's a numeric datatype. Even if the column names match, if the data types are different I suspect the column doesn't get populated.

answered Oct 20, 2011 at 13:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.