示例#1
0
        public static bool Update(SqlConnection connection, Item_Tax_Model model)
        {
            bool          returnValue = true;
            StringBuilder sQuery      = new StringBuilder();

            try
            {
                sQuery.Append(@"UPDATE a_Item_Tax SET
                             Tax = @Tax
                             WHERE idTax = @idTax ");
                connection.Open();

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = sQuery.ToString();
                    cmd.CommandType = CommandType.Text;

                    SqlParameter parm1 = new SqlParameter
                    {
                        ParameterName = "@idTax",
                        SqlDbType     = SqlDbType.Int,
                        Value         = model.idTax
                    };
                    cmd.Parameters.Add(parm1);

                    SqlParameter parm2 = new SqlParameter
                    {
                        ParameterName = "@Tax",
                        SqlDbType     = SqlDbType.NVarChar,
                        Value         = model.Tax
                    };
                    cmd.Parameters.Add(parm2);

                    if (cmd.ExecuteNonQuery() >= 1)
                    {
                        returnValue = true;
                    }

                    cmd.Dispose();
                    cmd.Parameters.Clear();
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }

            return(returnValue);
        }
示例#2
0
        public static List <Item_Tax_Model> RetrieveData(SqlConnection con)
        {
            List <Item_Tax_Model> dt       = new List <Item_Tax_Model>();
            StringBuilder         strQuery = new StringBuilder();

            strQuery.Append(@"SELECT Tax FROM a_Item_Tax");

            con.Open();
            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandText = strQuery.ToString();
                    cmd.CommandType = CommandType.Text;

                    var oreader = cmd.ExecuteReader();

                    while (oreader.Read())
                    {
                        Item_Tax_Model oModel = new Item_Tax_Model
                        {
                            Tax = (decimal)oreader["Tax"]
                        };

                        dt.Add(oModel);
                    }
                    oreader.Close();
                    cmd.Dispose();
                }
            }
            catch
            {
                SqlConnection.ClearAllPools();
            }
            con.Close();
            SqlConnection.ClearAllPools();
            return(dt);
        }