Beispiel #1
0
 public override Person GetPerson(ulong personID)
 {
     Person result = Person.Null;
     string statement = "SELECT * FROM Persons WHERE PersonID=@ID";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 sqlQuery.Parameters.AddWithValue("@ID", personID);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 if (sqlDR.Read())
                 {
                     Person p = new Person();
                     p.PersonID = (ulong)sqlDR["PersonID"];
                     p.MenuID = (ulong)sqlDR["MenuID"];
                     p.OrderID = (ulong)sqlDR["OrderID"];
                     return p;
                 }
                 result = Person.Null;
             }
         }
     }
     catch { result = Person.Null; }
     return result;
 }
Beispiel #2
0
 public override List<Person> GetAllPersons()
 {
     List<Person> persons = new List<Person>();
     string statement = "SELECT * FROM Persons";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 while (sqlDR.Read())
                 {
                     Person p = new Person();
                     p.PersonID = Convert.ToUInt64(sqlDR["PersonID"]);
                     p.MenuID = (sqlDR["MenuID"] != DBNull.Value) ? Convert.ToUInt64(sqlDR["MenuID"]) : (ulong?)null;
                     p.OrderID = Convert.ToUInt64(sqlDR["OrderID"]);
                     persons.Add(p);
                 }
                 return persons;
             }
             return null;
         }
     }
     catch { return null; }
 }