示例#1
0
        //get one violation
        public Violation getViolation(int id)
        {
            string sql_stmt;
            sql_stmt = "SELECT " +
                        "   violation_id,violation,description,price,last_modified " +
                        "FROM " +
                        "   violations " +
                        "WHERE " +
                        "   violation_id = @id";

            SqlCeConnection conn = new SqlCeConnection(this.conn_string);
            conn.Open();
            SqlCeCommand cmd = conn.CreateCommand();
            cmd.CommandText = sql_stmt;
            SqlCeResultSet result = cmd.ExecuteResultSet(ResultSetOptions.Insensitive);

            Violation violation = null;

            while (result.Read() != null)
            {
                violation = new Violation();
                violation.ViolationId = result.GetInt32(0);
                violation.ViolationName = result.GetString(1);
                violation.Description = result.GetString(2);
                violation.Price = result.GetDecimal(3);
                violation.LastModified = result.GetDateTime(4);

                break;
            }

            result.Close();
            conn.Close();

            return violation;
        }
示例#2
0
        //get violations
        public List<Violation> getAllViolations()
        {
            string sql_stmt;
            sql_stmt =  "SELECT " +
                        "   violation_id,violation,description,price,last_modified " +
                        "FROM " +
                        "   violations";

            SqlCeConnection conn = new SqlCeConnection(this.conn_string);
            conn.Open();
            SqlCeCommand cmd = conn.CreateCommand();
            cmd.CommandText = sql_stmt;
            SqlCeResultSet result = cmd.ExecuteResultSet(ResultSetOptions.Insensitive);

            List<Violation> violations = new List<Violation>();

            while (result.Read() != null)
            {
                Violation violation = new Violation();
                violation.ViolationId = result.GetInt32(0);
                violation.ViolationName = result.GetString(1);
                violation.Description = result.GetString(2);
                violation.Price = result.GetDecimal(3);
                violation.LastModified = result.GetDateTime(4);

                violations.Add(violation);
            }

            result.Close();
            conn.Close();

            return violations;
        }