Click here to Skip to main content
15,887,923 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Team

I am getting exception each time trying to save my changes to db from the table. Throw SqlException;binary or data be truncated. How do i resolve this issue?

What I have tried:

public ActionResult SubmitRegDetails(RegViewAndRoleViewModel eNtsaRegistration)
{


    if(ModelState.IsValid)
    {
        eNtsaRegistration.RegForm.Id = Guid.NewGuid();
        db.eNtsaRegForms.Add(eNtsaRegistration.RegForm);
        db.SaveChanges();
        return RedirectToAction("SaveRegForm");
    }


// Model
public class eNtsaRegForm
    {
        [Key]
        public Guid? Id { get; set; }
        public string Title { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Position { get; set; }
        public string Company { get; set; }
        public string StreetAddress { get; set; }
        public string StreetAddressLine { get; set; }
        public string City { get; set; }
        public string StateProvince { get; set; }
        public int ZipCode { get; set; }
        public string Country { get; set; }

        [Required(ErrorMessage = " This field is required")]
        [EmailAddress(ErrorMessage = "Invalid email address")]
        public string Email { get; set; }
        
        public int CellNumber { get; set; }
        public string DietaryRequirements { get; set; }


    }
Posted
Updated 22-Jul-20 4:59am

1 solution

The error message means what is says:
Quote:
"String or binary data would be truncated"

What it is telling you is that you have passed a string or an array of binary data that s too long for the column you are tried to INSERT it into - and as SQL is all about storing data, not throwing it away, it rightly complains that it can;t let you do that.

There are only two fixes for this:
1) Reduce the size of the string.
Or
2) Increase the column size.

We can't do either of those for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900