Going Mobile Listing #1: CE Database on the Desktop

String connectString="DataSource=F:\MobileApps\1105\Data\DBExample.sdf ";
DataClass dc = new DataClass();
dc.FirstName = "John";
dc.LastName = "Doe";
dc.PatientNumber = "100100100";

using (SqlCeConnection conn = new SqlCeConnection(connectString))
{
  using (SqlCeCommand cmd = new SqlCeCommand())
  {
    cmd.CommandText = "INSERT Patients";
    cmd.CommandText += " (cFirstName, clastName, cPatientNumber)";
    cmd.CommandText += String.Format(" VALUES('{0}', '{1}', '{2}')",     
    dc.FirstName, dc.LastName, dc.PatientNumber);
    cmd.CommandType = CommandType.Text;
    cmd.Connection = conn;

    try
    {
      conn.Open();
      cmd.ExecuteNonQuery();
    }
    catch (SqlCeException ex)
    {
    }
  }
}

comments powered by Disqus
Most   Popular
Upcoming Events

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.