0

Ok so here's the thing, I used to read in data from an excel file and bulk copy this data into a SQL table and everything worked fine. But now, my source file changed, so now i get data from a other excel file. Both file look exactly the same, I can still read in the data through the program, but now, when I bulk copy the data to a SQL table, instead of inserting the values, it inserts "NULL" into the column...I just don't know what is going on. My program still works fine with the other source file.

My BulkCopy Code:

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(thisConnection))
      {
          bulkCopy.DestinationTableName =
            "tbl_" + Release.Text + "_NEW_VERSION_FILE";

         try
           {
               bulkCopy.WriteToServer(AddTermTable);
           }

         catch (Exception ex)
           {
               Console.WriteLine(ex.Message);
               thisConnection.Close();
               Console.ReadLine();
           }

         finally
           {
                thisConnection.Close();
           }
      } 

Attached (GUI) , you will see a picture of my GUI that has the data from the New source file attached to a datagrid.
The second attachment is a picture of how it looks in SQL.

Can anyone help me understand this?

Attachments GUI.jpg 44.27 KB SQL_Output.jpg 54.05 KB
2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by Cameronsmith63
0

If you're still interested, in the left screen grab you've highlight all but there WHERE clause which means that only the highlighted code will be executed and nulls will be returned.

0

yeah i made a stupid mistake, bulk copy doesn't care which column it copies the data to, as long as the number of columns for the source and destination is the same, so the data did copy to the first column of the table, which is not shown with my sql query.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.