コード例 #1
0
        public bool delete(BuyBLL u)
        {
            bool          issuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "DELETE FROM PRODUCTS WHERE id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", u.id);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    issuccess = true;
                }
                else
                {
                    issuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(issuccess);
        }
コード例 #2
0
        public BuyBLL GetProductsForTransaction(string keyword)
        {
            //Create an object of productsBLL and return it
            BuyBLL p = new BuyBLL();
            //SqlConnection
            SqlConnection conn = new SqlConnection(myconnstrng);
            //Datatable to store data temporarily
            DataTable dt = new DataTable();

            try
            {
                //Write the Query to Get the detaisl
                string sql = "SELECT name, name_of_mfg, batch_no,price, expiry_date FROM products WHERE name LIKE '%" + keyword + "%'";
                //Create Sql Data Adapter to Execute the query
                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

                //Open DAtabase Connection
                conn.Open();

                //Pass the value from adapter to dt
                adapter.Fill(dt);

                //If we have any values on dt then set the values to productsBLL
                if (dt.Rows.Count > 0)
                {
                    p.name        = dt.Rows[0]["name"].ToString();
                    p.price       = decimal.Parse(dt.Rows[0]["price"].ToString());
                    p.expiry_date = DateTime.Parse(dt.Rows[0]["expiry_date"].ToString());
                    p.name_of_mfg = dt.Rows[0]["name_of_mfg"].ToString();
                    p.batch_no    = dt.Rows[0]["batch_no"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close Database Connection
                conn.Close();
            }

            return(p);
        }