private void mitemSubmitSQL_Click(object sender, EventArgs e) { // Create a remote data access object SqlCeRemoteDataAccess rdaNW = new SqlCeRemoteDataAccess(strURL, strConnLocal); try { // Have RDA: // Create local tables named Categories and // ErrorCategories. // Connect to the remote server and submit // the changes. rdaNW.LocalConnectionString = strConnLocal; rdaNW.InternetUrl = strURL; rdaNW.InternetLogin = ""; rdaNW.InternetPassword = ""; rdaNW.SubmitSql( "INSERT Categories (CategoryName, Description)" + "VALUES ('New Category II', 'From SubmitSQL')", strConnRemote); } catch (SqlCeException exSQL) { HandleSQLException(exSQL); } finally { rdaNW.Dispose(); } }
private void mitemPull_Click(object sender, EventArgs e) { // Create a remote data access object SqlCeRemoteDataAccess rdaNW = new SqlCeRemoteDataAccess(strURL, strConnLocal); try { // Have RDA: // Create local tables named Categories and // ErrorCategories. // Connect to the remote server and submit the // SELECT statement. // Place the results in the local Categories table. rdaNW.LocalConnectionString = strConnLocal; rdaNW.InternetUrl = strURL; rdaNW.InternetLogin = ""; rdaNW.InternetPassword = ""; rdaNW.Pull("Categories", "SELECT CategoryID, CategoryName " + " FROM Categories", strConnRemote, RdaTrackOption.TrackingOnWithIndexes, "ErrorCategories"); } catch (SqlCeException exSQL) { HandleSQLException(exSQL); } finally { rdaNW.Dispose(); } // The Identity property seed value of the new table // is at 1, even after the retrieved rows have // been added to the table. "Fix" it. SqlCeConnection connLocal = new SqlCeConnection(strConnLocal); connLocal.Open(); SqlCeCommand cmndLocal = new SqlCeCommand(); int intMaxCategoryID; try { cmndLocal.Connection = connLocal; // Retrieve the highest CategoryID in the table. cmndLocal.CommandText = "SELECT max(CategoryID) FROM Categories"; string strMaxCategoryID = cmndLocal.ExecuteScalar().ToString(); intMaxCategoryID = int.Parse(strMaxCategoryID); // set the seed one higher. cmndLocal.CommandText = "ALTER TABLE Categories " + "ALTER COLUMN CategoryID IDENTITY (" + (intMaxCategoryID + 1).ToString() + ",1)"; cmndLocal.ExecuteNonQuery(); } catch (SqlCeException exSQL) { HandleSQLException(exSQL); } finally { connLocal.Close(); } }