// GET: image/Create public ActionResult addimage() { PieceJoint b1 = new PieceJoint(); List <file> list = new List <file>(); const string connect = @"Server=WAHID;Database=HELPDESK3;Trusted_Connection=True;"; using (var conn = new SqlConnection(connect)) { var qry = "SELECT [IdPiece],[filename] FROM PieceJoint "; var cmd = new SqlCommand(qry, conn); conn.Open(); SqlDataReader result = cmd.ExecuteReader(); while (result.Read()) { list.Add(new file( result.GetInt32(0), result.GetString(1) )); } } ViewBag.list = list; return(View(b1)); }
public ActionResult addimage(PieceJoint model, HttpPostedFileBase image1) { var db = new HELPDESK3Entities(); if (image1 != null) { model.img = new byte[image1.ContentLength]; model.filename = image1.FileName; model.type = "" + image1.GetType(); image1.InputStream.Read(model.img, 0, image1.ContentLength); } db.PieceJoint.Add(model); db.SaveChanges(); ViewBag.filename = image1.FileName; List <file> list = new List <file>(); const string connect = @"Server=WAHID;Database=HELPDESK3;Trusted_Connection=True;"; using (var conn = new SqlConnection(connect)) { var qry = "SELECT [IdPiece],[filename] FROM PieceJoint "; var cmd = new SqlCommand(qry, conn); conn.Open(); SqlDataReader result = cmd.ExecuteReader(); while (result.Read()) { list.Add(new file( result.GetInt32(0), result.GetString(1) )); } } ViewBag.list = list; return(View(model)); }