• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer
  • Home
  • About
    • linkedin
    • twitter
  • Archive
  • Technical youtube Channel
  • Recommended Readings
  • Free Courses
    • Fixed Asset management Course
    • Financial Modules

Ali Raza Zaidi

A practitioner’s musings on Dynamics 365 Finance and Operations

execute stored procedure with parameters dynamics ax 2012

October 20, 2014 by alirazazaidi

During in one of my assignment, I have to call sql server stored procedure from X++ code. There is little tricky to call stored procedure with parameters. Following code will help me to call stored procedure with Parameters. Consider sp_StudentCreates a stored procedure with three parameters, first two string and last one is date.

private void InsertStudent( StudentDC  _dc)
{
    LoginProperty loginProperty;

OdbcConnection odbcConnection;

Statement statement;

ResultSet resultSet;

LoginProperty myLoginProperty;

str sql, criteria;

int output;

SqlStatementExecutePermission perm;

str myUserName="dynamicworld\\aliraza.zaidi";

str myPassword="xyz";

str myConnectionString;

myConnectionString=strfmt("UID=%1;PWD=%2",myUserName,myPassword);

myLoginProperty = new LoginProperty();

myLoginProperty.setServer("dynamicworld.com");

myLoginProperty.setDatabase("studentDb");

myLoginProperty.setOther(myConnectionString);



//Create a connection to external database.

odbcConnection = new OdbcConnection(myLoginProperty);



if (odbcConnection)

{



    sql = "Execute sp_StudentCreates   '"+_dc.parmFirstName())+"','"+_dc.parmLastMame())+"','"+date2str(_dc.parmDate(),321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4)+"'";
 info(sql);

//Assert permission for executing the sql string.

perm = new SqlStatementExecutePermission(sql);

perm.assert();



//Prepare the sql statement.

statement = odbcConnection.createStatement();

output = statement.executeUpdate(sql);






statement.close();

}

else

{

error("Failed to log on to the database through ODBC.");
}

}

Related

Filed Under: Dynamics AX 2012, Dynamics Ax 2012 Technical Side Tagged With: Dynamic AX 2012, Dynamics Ax 2012, X++

Primary Sidebar

Categories

  • Accounts Payable (2)
  • Advance Warehouse (1)
  • Books (6)
  • Certification Guide (3)
  • Customization Tips for D365 for Finance and Operations (57)
  • D365OF (54)
  • Dynamics 365 (52)
  • Dynamics 365 for finance and operations (123)
  • Dynamics 365 for Operations (140)
  • Dynamics AX (AX 7) (133)
  • Dynamics AX 2012 (274)
  • Dynamics Ax 2012 Forms (13)
  • Dynamics Ax 2012 functional side (16)
  • Dynamics Ax 2012 Reporting SSRS Reports. (31)
  • Dynamics Ax 2012 Technical Side (51)
  • Dynamics Ax 7 (64)
  • Exam MB-330: Microsoft Dynamics 365 Supply Chain Management (6)
  • Favorites (12)
  • Financial Modules (6)
  • Functional (6)
  • Implementations (1)
  • Lifecycle Services (1)
  • Management Reporter (1)
  • MS Dynamics Ax 7 (64)
  • MVP summit (1)
  • MVP summit 2016 (1)
  • New Dynamics Ax (19)
  • Non Defined (9)
  • Power Platform (6)
  • Procurement (3)
  • procurement and sourcing (3)
  • Product Information Management (1)
  • Product Management (2)
  • Production Control D365 for Finance and Operations (8)
  • Sale Order Process (8)
  • Sale Order Processing (8)
  • Sales and Distribution (5)
  • Tips and tricks (275)
  • Uncategorized (165)
  • Upgrade (1)
  • Web Cast (7)
  • White papers (4)

Secondary Sidebar

Footer

Tags

Account receivable AIF Aif Services Apps for Dynamics 365 for Operations asp.net AX 7 AX 7 CTP 8 BizTalk 2010 BizTalk Errors c# Customization in Dynamics 365 d d365 for finance and operations D365 for Operations Dynamic AX 2012 Dynamics 365 for finance and operations Dynamics 365 for Operations Dynamics Ax Dynamics Ax 7 Dynamics Ax 2012 Dynamics Ax 2012 development 2 Dynamics Ax 2012 functional side Dynamics Ax 2012 R3 Dynamics Ax 2012 Reporting SSRS Reports. Dynamics Ax 2102 Dynamics Ax tips and tricks ER Diagrams of Dynamics Ax 2012 tables Exam MB-330: Microsoft Dynamics 365 Supply Chain Management Excel Add ins financial Dimension Microsoft Dynamics 365 for Operations MSDYN365FO New Dynamics Ax Power BI Power BI tutorial procurement in dynamics ax 2012 Product Management Sales and distribution SQL Server 2008 SSRS Tips and tricks Workflow WorkFlow in AX X++ X++ tips

Copyright © 2023 · Magazine Pro On Genesis Framework · WordPress · Log in