Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have got an application that reads an Excel Spreadsheet into a DataTable. I am now struggling to take the data from that DataTable and add it into my local SDF file.

I am using C#

Any help would be much appreciated :)

C#
private bool WriteOutDataAsSdf(ref string sdfOutputFile, ref DataTable dataTable)
        {
            SqlCommand commandRowCount = new SqlCommand("SELECT COUNT(*) FROM " + "sdf.PLU Codes;", connection);

            long countStart = Convert.ToInt32(commandRowCount.ExecuteScalar());

            MessageBox.Show("Starting row count = " + countStart);

            using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
            {
                bulkCopy.DestinationTableName = "sdf.PLU Codes";
                try
                {
                    // Write from the source to the destination.
                    bulkCopy.WriteToServer(dt);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }





Cheers Glen.
Posted
Comments
Christian Graus 9-Nov-13 23:42pm    
What is 'dt' ? It's not defined anywhere in this code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900