using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace CoffeeShopProject { public partial class AddProduct : Form { private CoffeeShopDatabaseEntities cse = new CoffeeShopDatabaseEntities(); private Byte[] byteBLOBData; public AddProduct() { InitializeComponent(); cboCategory.DataSource = cse.tblProductTypes; cboCategory.DisplayMember = "Description"; cboCategory.ValueMember = "ProductType"; } private void btnUpload_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { FileStream fsBLOBFile = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); byteBLOBData = new Byte[fsBLOBFile.Length]; fsBLOBFile.Read(byteBLOBData, 0, byteBLOBData.Length); fsBLOBFile.Close(); MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); pxbImage.Image = Image.FromStream(stmBLOBData); } } private void btnSave_Click(object sender, EventArgs e) { tblProduct products = new tblProduct(); products.Description = txtDescription.Text; products.Price = int.Parse(txtPrice.Text); products.Image = byteBLOBData; products.ProductType = (int)cboCategory.SelectedValue; cse.SaveChanges(); MessageBox.Show("Record Saved!"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)