Esempio n. 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public void CreateObjectInDB(Person obj)
 {
     using (SqlConnection conn = new SqlConnection(_connectionString))
     {
         using (SqlCommand cmd = new SqlCommand(_SqlCommandInsertInto, conn))
         {
             conn.Open();
             AddParameters(cmd, obj);
             cmd.ExecuteNonQuery();
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="recID"></param>
 /// <returns></returns>
 public void DeleteObjectFromDB(Person obj)
 {
     using (SqlConnection conn = new SqlConnection(_connectionString))
     {
         using (SqlCommand cmd = new SqlCommand(_SqlCommandDelete,conn))
         {
             conn.Open();
             AddParameters(cmd, obj);
             cmd.ExecuteNonQuery();
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="obj"></param>
 private void AddParameters(SqlCommand cmd, Person obj)
 {
     cmd.Parameters.AddWithValue("@firstName", obj.FirstName);
     cmd.Parameters.AddWithValue("@lastName", obj.LastName);
     cmd.Parameters.AddWithValue("@position", obj.Position);
     cmd.Parameters.AddWithValue("@age", obj.Age);
     cmd.Parameters.AddWithValue("@recID", obj.RecID);
 }