Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
error: An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code.


this error occurred when using TimeSpan for saving in database...!!!

C#
var db = new Online_GameEntities();
            TimeSpan ts = new TimeSpan(0, 0, 0);
            DateTime dtnow = DateTime.Now;
            int h = dtnow.Hour;
            int m = dtnow.Minute;
            int s = dtnow.Second;
            int day = dtnow.Day;
            TimeSpan tsnow = new TimeSpan(day, h, m, s);
            TimeSpan tscreate = new TimeSpan(0, 12, 25);
            TimeSpan tscreated = tsnow.Add(tscreate);

            tbl_building insertbuild = new tbl_building();
            insertbuild.createdtime = (TimeSpan)tscreated;
            insertbuild.createtime = (TimeSpan)tscreate;
            insertbuild.levels = 1;
            insertbuild.c_id = "ttyuyt";
            insertbuild.firststate = true;
            insertbuild.name = "";          
            insertbuild.x =5;
            insertbuild.y = 5;
            insertbuild.image = "b1.jpg" + "_" + 5;

            db.tbl_building.Add(insertbuild);
            db.SaveChanges();
Posted
Updated 24-Dec-14 4:52am
v6
Comments
CHill60 24-Dec-14 10:38am    
What is the error and in which line? By the way - it is important only to you, it's best not to put that into your subject line
Member 11333235 24-Dec-14 10:46am    
i forgot it . i updated.
CHill60 24-Dec-14 10:48am    
Put a try-catch around the db.SaveChanges() and put a breakpoint in the catch - examine the inner exception with the debugger - it should give you some more clues
CHill60 24-Dec-14 11:19am    
What datatype is the createdtime, createtime in the database?
Member 11333235 25-Dec-14 1:27am    
time(7)

1 solution

There is no such data type in SQL that fits TimeSpan...
From the names of your filed I conclude that you have DATETIME SQL data type - use the same for your data in your C# code too...
 
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