0

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

4
  • 1
    The local SQL Server CE connection must use SqlCeConnection and SqlCeCommand !! Commented Aug 7, 2016 at 15:56
  • 1
    This has nothing to do with VS2008 - the problem is: SqlBulkCopy is only for "real" SQL Server (Express and others) - but NOT for the Compact Edition (which is really a totally different, separate product). But maybe this project on CodePlex could be of help to you Commented Aug 7, 2016 at 17:03
  • @jobin Can we know what kind of exception you are getting while compiling/executing the above code?. Commented Aug 8, 2016 at 11:01
  • SqlBulkCopy missing reference Commented Aug 8, 2016 at 11:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.