简体   繁体   中英

DbUpdateException occuring when adding a record to a database C#

This is the first time I have used EntityModels and I am having trouble adding a new record to the database. An 'DbUpdateException' occurs in the SaveChanges() method, also I can not find the "Inner Exception".

DbUpdateException

    //this is the code in the Bookings class
    public void Save()
    {
        InsightEntities ie = new InsightEntities();

        ie.Bookings.Add(this);

        try
        {
            ie.SaveChanges(); //Error Occuring Here
        }
        catch (Exception err)
        {
            throw;
        }
    }

In case you need it here is the record I am trying to add: (BookingId & DateEntered have default values in the database)

类:预订

Thanks in advance

Turns out it wasn't inserting the new record as it couldn't convert DateTime to smalldatetime,

Fixed this by changing the database column types to DateTime

All works now! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM