In C# or vb.net we can connect and perform on Dynamics Ax classes and Tables with business connector.
This technique is widely used in Dynamics Ax 2009 and rarely I saw these used in ax 2012. Its depends on
Requirement.
Consider following scenario where I have to perform different operations on following custom table.
Create a New console application in C#
For this propose you have to add the reference of dll “Microsoft.Dynamics.BusinessConnectorNet.dll”
Usually you can find it following location.
C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\
Now following code will help perform different operation on Dynamics Ax Table through proxy classes.
Create
try { Axapta ax; AxaptaRecord _recoder; ax = new Axapta(); ax.Logon("Usmf", null, null, null); _recoder = ax.CreateAxaptaRecord("StudentInfoTable"); _recoder.set_Field("Address", "Lahore"); _recoder.set_Field("DateOfBirth", new DateTime(1979, 4, 9)); _recoder.set_Field("FirstName", "Ali "); _recoder.set_Field("LastName", "Zaidi"); _recoder.Insert(); } catch (Exception ex) { Console.WriteLine(ex.Message); }
Read all
try { Axapta ax; AxaptaRecord _recoder; ax = new Axapta(); ax.Logon("Usmf", null, null, null); _recoder = ax.CreateAxaptaRecord("StudentInfoTable"); _recoder.ExecuteStmt("Select * from %1"); while (_recoder.Found) { Console.WriteLine("FirstName " +_recoder.get_Field("FirstName")); Console.WriteLine("LastName " + _recoder.get_Field("LastName")); _recoder.Next(); } Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); }
Read specific
try { Axapta ax; AxaptaRecord _recoder; ax = new Axapta(); ax.Logon("Usmf", null, null, null); _recoder = ax.CreateAxaptaRecord("StudentInfoTable"); _recoder.ExecuteStmt("Select * from %1 where %1.FirstName=='Ali'"); while (_recoder.Found) { Console.WriteLine("FirstName " +_recoder.get_Field("FirstName")); Console.WriteLine("LastName " + _recoder.get_Field("LastName")); _recoder.Next(); } Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); }
Update
try { Axapta ax; AxaptaRecord _recoder; ax = new Axapta(); ax.Logon("Usmf", null, null, null); _recoder = ax.CreateAxaptaRecord("StudentInfoTable"); _recoder.ExecuteStmt("Select forupdate * from %1 where %1.FirstName=='Ali'"); while (_recoder.Found) { Console.WriteLine("FirstName " +_recoder.get_Field("FirstName")); Console.WriteLine("LastName " + _recoder.get_Field("LastName")); ax.TTSBegin(); _recoder.set_Field("LastName", " Raza Zaidi"); _recoder.Update(); ax.TTSCommit(); _recoder.Next(); } Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); }
Delete
nbsp; Axapta ax; AxaptaRecord _recoder; ax = new Axapta(); ax.Logon("Usmf", null, null, null); _recoder = ax.CreateAxaptaRecord("StudentInfoTable"); _recoder.ExecuteStmt("Select forupdate * from %1 where %1.FirstName=='Ali'"); while (_recoder.Found) { Console.WriteLine("FirstName " +_recoder.get_Field("FirstName")); Console.WriteLine("LastName " + _recoder.get_Field("LastName")); ax.TTSBegin(); _recoder.set_Field("LastName", " Raza Zaidi"); _recoder.Delete(); ax.TTSCommit(); _recoder.Next(); } Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); }