Example #1
0
 protected void txtID_TextChanged(object sender, EventArgs e)
 {
     /*get data for the rest of the boxes to fill in */
     try
     {
         product       = Functions_Product.getOneProductById(Convert.ToInt32(txtID.Text));
         txtTitle.Text = product.Title;
         txtDesc.Text  = product.Description;
         txtQuan.Text  = product.Quantity.ToString();
         txtCost.Text  = product.Cost.ToString();
     }
     catch (Exception ex)
     {
         globalMethods.printDebug(ex.ToString());
     }
 }
        public static Record_Product getOneProductById(int ProductID)
        {
            SqlConnection conn = new SqlConnection(
                "Data Source=s08.everleap.com;" +
                "Initial Catalog=DB_5349_evaswebsite;" +
                "User ID=DB_5349_evaswebsite_user;" +
                "Password="******"Select * from tblProducts where ID = @ProductID";
                    command.CommandType = CommandType.Text;
                    command.CommandText = strSQL;
                    command.Parameters.AddWithValue("@ProductID", ProductID);
                    /*Return one product where ID matches*/
                    SqlDataReader  reader  = command.ExecuteReader();
                    Record_Product product = new Record_Product();
                    while (reader.Read())
                    {
                        product.Title       = reader.GetString(1);
                        product.Description = reader.GetString(2);
                        product.Quantity    = reader.GetInt32(3);
                        product.Cost        = reader.GetDouble(4);
                        product.PicturePath = reader.GetString(5);
                    }
                    conn.Close();
                    globalMethods.printDebug("get one product set");
                    return(product);
                }
                catch (Exception ex)
                {
                    globalMethods.printDebug($"Get One Product Error:\n {ex}");
                    return(null);
                }
            }
        }