Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi
i have a really important question , i've worked with linq to entity many times but this time i confront with a problem that i cant save any record in database!!!!!!

THIS IS A PART OF MY CODE
C#
DatabaseEntities ndb = new DatabaseEntities();
M_Info mn = new M_Info();
            mn.EDate = "m";
            mn.LDay = "s";
            mn.LHour = "s";
            mn.MType = "slkd";
            mn.SDate = "sajkc";
            mn.Who = 1;
           
            ndb.AddToM_Info(mn);
            ndb.SaveChanges();

but no record will save!!!!! even it didnt throw any exeption, i donno what to do now
Posted
Updated 24-Oct-12 2:34am
v2
Comments
Herman<T>.Instance 24-Oct-12 10:57am    
where is the ndb.InsertOnSubmit()?
Rajesh Kariyavula 25-Oct-12 1:40am    
Is this all your code for saving a record?
Saraniraj 25-Oct-12 2:54am    
you can try addobject coding


ndb.AddToM_Info.AddObject(mn);
ndb.SaveChanges();

use the breakpoints and debug the application , watch carefully that actulally you save records in db or not?

http://msdn.microsoft.com/en-us/library/gg509017.aspx[^]


Thanks,
Ambesha
 
Share this answer
 
Try using AddObject method on M_Info as suggested by RajKumar

e.g : ndb.M_Info.AddObject(mn);
ndb.SaveChanges();

Also check if the M_Info table has a primary key.
 
Share this answer
 
Hi,

Please use this code may it will solve your problem:-

C#
using(DatabaseEntities ndb = new DatabaseEntities())
{
M_Info mn = new M_Info()
           {
            mn.EDate = "m",
            mn.LDay = "s",
            mn.LHour = "s",
            mn.MType = "slkd",
            mn.SDate = "sajkc",
            mn.Who = 1,
           };
           
            ndb.AddToM_Info(mn);
            ndb.SaveChanges();
}
 
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