title: Insert data into Sql Compact
body: <p>I have Handheld device that connect to Sql Server database, read the Sql server data and get it on the SQL Compact database that is located on device. This is my code:</p>
  
  <pre><code>public void InsertData() // Function insert data into SQL commapct database
  {
      dt = new DataTable();
      dt = SqlServer_GetData_dt("Select id_price, price, id_item  from prices", SqlCeConnection); // get data form sql server
      if (dt.Rows.Count &gt; 0)
      {
          for (int i = 0; i &lt; dt.Rows.Count; i++)
          {
              string sql = "";
              sql = "insert into prices" +
                  " ( id_prices, price,id_item) values('"
                      + dt.Rows[i]["id_price"].ToString().Trim() + "', '"
                      + dt.Rows[i]["price"].ToString().Trim() + "', '"
                      + dt.Rows[i]["id_item"].ToString().Trim() + "')";
  
              obj.SqlCE_WriteData_bit(sql, connection.ConnectionString);//insert into sql compact
          }
      }
  
  
  }
  
  public DataTable SqlServer_GetData_dt(string query, string conn)
  {
      try
      {
          DataTable dt = new DataTable();
          string SqlCeConnection = conn;
          SqlConnection sqlConnection = new SqlConnection(SqlCeConnection);
          sqlConnection.Open();
          {
  
              SqlDataReader darSQLServer;
              SqlCommand cmdCESQLServer = new SqlCommand();
              cmdCESQLServer.Connection = sqlConnection;
              cmdCESQLServer.CommandType = CommandType.Text;
              cmdCESQLServer.CommandText = query;
              darSQLServer = cmdCESQLServer.ExecuteReader();
              dt.Load(darSQLServer);
              sqlConnection.Close();
          }
          return dt;
      }
      catch (Exception ex)
      {
  
          MessageBox.Show(ex.ToString());
          DataTable dt = new DataTable();
          return dt;
  
      }
  }
  public object SqlCE_WriteData_bit(string query, string conn)
  {
      try
      {
          string SqlCeConnection = conn;
          SqlCeConnection sqlConnection = new SqlCeConnection(SqlCeConnection);
          if (sqlConnection.State == ConnectionState.Closed)
          {
              sqlConnection.Open();
          }
          SqlCeCommand cmdCESQLServer = new SqlCeCommand();
          cmdCESQLServer.Connection = sqlConnection;
          cmdCESQLServer.CommandType = CommandType.Text;
          cmdCESQLServer.CommandText = query;
          object i = cmdCESQLServer.ExecuteScalar();
          sqlConnection.Close();
          return i;
  
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.ToString());
          return 0;
      }
  }
  </code></pre>
  
  <p>This is all work fine but the problem is that all this work very slow. I have 20 000 row that's need to be inserted into SQL compact database.</p>
  
  <p>Is there any way for faster insert?</p>
  
  <p>Thanks.</p>