0

I am using Local data Cache (.sdf) in my application. I want to store data locally. How to do that. thereafter i will sync local data with online data. How should i make connection to local database(.sdf) and saving records in it.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Mohan
  • 907
  • 5
  • 22
  • 45

1 Answers1

2

Use database like this:

string localDatabasePath = @"FOLDER";
string localDatabaseName = "FILE.sdf";
string localDatabasePass = "WhyDoYouCare";
string localDatabaseUsersTable = "userstable";

                SqlCeConnection localDatabaseConn = new SqlCeConnection("Data Source = " + localDatabasePath + "\\" + localDatabaseName + "; Password=" + localDatabasePass);
                localDatabaseConn.Open();
                SqlCeCommand localDatabaseCmd = localDatabaseConn.CreateCommand();
                localDatabaseCmd.CommandText = "SELECT something FROM " + localDatabaseUsersTable + " WHERE username='" + Username + "'";
                localDatabaseCmd.ExecuteNonQuery();
                SqlCeDataReader localDatabaseRdr = localDatabaseCmd.ExecuteReader();

Use Smart Client Software Factory for disconnected architecture and synchronization. For updating to central database when connected to network, you will have to write web-service usually and update data objects.

pooja_cute
  • 246
  • 1
  • 3
  • 7