Пример #1
0
        public override bool Insert(iVehiclecategories c)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                string     q   = string.Empty;
                SqlCommand cmd = new SqlCommand(q, conn);

                q = @"INSERT INTO vehiclecategories (name, vtype) VALUES ( @pName, @pVtype)";

                cmd.CommandText = q;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@pName", SqlDbType.VarChar).Value  = c.Name;
                cmd.Parameters.Add("@pVtype", SqlDbType.VarChar).Value = c.VehicleType;
                try
                {
                    conn.Open();
                    int rc = ExecuteNonQuery(cmd);
                    return(rc == 1);
                }
                catch (SqlException ex)
                {
                    ErrorHandler.writeSQLExceptionToLogFile(ex);
                    return(false);
                }
            }
        }
Пример #2
0
        public override bool Update(iVehiclecategories c)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                string q = string.Empty;

                q = @"UPDATE vehiclecategories SET 
                    name = @pName,
                    vtype = pVtype 
                    WHERE id = @pid";

                SqlCommand cmd = new SqlCommand(q, conn);
                cmd.CommandText = q;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@pName", SqlDbType.VarChar).Value  = c.Name;
                cmd.Parameters.Add("@pVtype", SqlDbType.VarChar).Value = c.VehicleType;
                try
                {
                    conn.Open();
                    int rc = ExecuteNonQuery(cmd);
                    return(rc == 1);
                }
                catch (SqlException ex)
                {
                    ErrorHandler.writeSQLExceptionToLogFile(ex);
                    return(false);
                }
            }
        }
        protected virtual iVehiclecategories GetVehiclecategoriesFromReader(IDataReader reader, bool singleRecord)
        {
            if (singleRecord)
            {
                reader.Read();
            }
            iVehiclecategories vehiclecategories = new iVehiclecategories(
                Convert.ToInt32(reader["id"]),
                reader["name"].ToString(),
                reader["vtype"].ToString()
                );

            return(vehiclecategories);
        }
 public abstract bool Update(iVehiclecategories c);
 public abstract bool Insert(iVehiclecategories c);