-1

This action method is uploading the image, when it executes dbx.SaveChanges(); method then it throws the exception. "String or binary data would be truncated. The statement has been terminated"

    public ActionResult FileUpload(int id, HttpPostedFileBase file)
    {
        dbCRMEntities dbx = new dbCRMEntities();
        CONTACT con = new CONTACT();
        if (file != null)
        {
            string pic = System.IO.Path.GetFileName(file.FileName);
            string path = System.IO.Path.Combine(
                                   Server.MapPath("~/Content/Images"), pic);
            // file is uploaded
            file.SaveAs(path);
            //con.NAME = path;
            con = dbx.CONTACTS.FirstOrDefault(Id => id == Id.CONTACT_ID);
            con.IMAGE = path;
            dbx.SaveChanges();

        }

        return RedirectToAction("Index", "Home");
    }

Here image is type of string for storing the path. Please guide what changes should I make?

adiga
  • 34,372
  • 9
  • 61
  • 83
Umair
  • 65
  • 7

1 Answers1

1

That generally happens when try to insert wrong datatyp/data length into some column of sql table. e.g: if your column is varchar[100] and you are trying to insert longer paragraphs. check the values and respective table columns carefully, the error lies somewhere there

Kumar Manish
  • 3,746
  • 3
  • 37
  • 42
  • yes it was only data length problem, I make it varchar(100) and its working now, thanks Kumar Manish – Umair Dec 26 '14 at 10:29