Search code examples
c#sql-serversql-server-ce

SQL Server to SQL Server CE table data copy using SqlBulkCopy


I'm working on a Windows CE application, and I need to copy server table data to SQL Server CE database (local) using C# programming. I'm using Visual Studio 2008, SQL Server 2008 for the development.

Below is the code I'm working with, but it seems in VS2008 SqlBulkCopy isn't supported. Do we have any alternatives to achieve this functionality?

SqlConnection source = new SqlConnection(Con_s);// server connection string SQL Server

SqlCeConnection destination = new SqlConnection(Con_l);// Local connection string SQL Server CE DB
SqlCeCommand cmd = new SqlCeCommand("DELETE FROM ProductList", destination);
source.Open();

destination.Open();
cmd.ExecuteNonQuery();

cmd = new SqlCommand("SELECT * FROM Products", source);

SqlDataReader reader = cmd.ExecuteReader();

SqlBulkCopy bulkData = new SqlBulkCopy(destination);
bulkData.DestinationTableName = "ProductList";

bulkData.WriteToServer(reader);

bulkData.Close();
destination.Close();
source.Close();

Add: I have included both using System.Data.SqlClient; & using System.Data; in the code


Solution

  • Since I cannot paste image in the comments,I am including it as answer. SqlBulkcopy is present under System.Data.SqlClient namespace. Just navigate to SqlBulkcopy namespace,you must get navigated to the below enter image description here

    If not I think your dll is corrupted may be you need to reload new one.