0

I have company table where values are inserted

public int SaveCompany(Company objCompany)
{

  int CompanyID = 0

  try
  {
    using (var context = new Cubicle_EntityEntities())
    {
      context.Companies.Add(objCompany);        //add entity to the add method
      int res = context.SaveChanges();       //insert it into table
      if (res > 0)
      {
        Debug.WriteLine("Data Inserted Successfully");
      }
      else
      {
        Debug.WriteLine("Try Again");
      }
      CompanyID = objCompany.CompanyId;
      Debug.WriteLine("CompanyId " + CompanyID);

    }
  }
  catch (Exception ex)
  {

     CompanyID = 0;
     bool rethrow = UserInterfaceExceptionHandler.HandleException(ref ex);
     throw ex;
   }       

   return CompanyID;
 }      

Every time I get res 1,but data not inserted in table.

mcalex
  • 6,628
  • 5
  • 50
  • 80
user11887906
  • 111
  • 1
  • 1
  • 6

0 Answers0