Using code to read data from model


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Sage.Accounting.Application application = null;
  2.  
  3. try
  4. {
  5. application = new Sage.Accounting.Application();
  6.  
  7. application.Connect("3", "");
  8.  
  9. application.ActiveCompany = application.Companies[1];
  10.  
  11. // Create an instnace of the model I want - in this case "Sage 200 Accounts"
  12. DataModel model = (new DataModelProvider()).CreateNew("Sage 200 Accounts",null);
  13.  
  14. // Bind the connection
  15. bool bound=model.BindConnection(null);
  16.  
  17. //Retrieve the context from the model
  18. Sage.Accounting.DataModel.DataContext context=(Sage.Accounting.DataModel.DataContext)(model.ModelContext);
  19.  
  20. // The context for the Sage 200 Accounts model contains all of the entities you would expect
  21. // in addition to many calculated fields and projections
  22. context.SLCustomerAccounts.Select(
  23. s=>new
  24. {
  25. s.SLCustomerAccountID,
  26. s.CustomerAccountNumber,
  27. s.CustomerAccountShortName,
  28. s.AccountBalance,
  29. s.CreditLimit,
  30. s.SYSCurrencyID
  31. }
  32. )
  33. .Dump();
  34. }
  35. catch (System.Exception exception)
  36. {
  37. exception.Message.Dump();
  38. }
  39. finally
  40. {
  41. if (application != null)
  42. {
  43. application.Disconnect();
  44. }
  45. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.