Using new DotNet datatype to call stored procedure from Nav

gstroud
Member Posts: 3
Has anyone done any work on call stored procedures from codeunits using the new DotNet datatype?
I'm having a problem with the SqlCommand objects CommandType property accepting "StoredProcedure". The property is an Enumeration type so in order to set it to StoredProcedure you have to use the value of 1.
Debugging confirms this I set it then step over it and it doesn't take.
Thanks
Greg
I'm having a problem with the SqlCommand objects CommandType property accepting "StoredProcedure". The property is an Enumeration type so in order to set it to StoredProcedure you have to use the value of 1.
Debugging confirms this I set it then step over it and it doesn't take.
Thanks
Greg
0
Comments
-
I was able to solve it. There were a couple of things that through me off. One the CommandType didn't have a constructor. Secondly the enum types are incorrectly documented.
Here is how you do it (Example):
SQLCmd := SQLCmd.SqlCommand('NameOfStoredProcedure',SQLConnection); //Creates the SqlCommand object
CmdType := SQLCmd.CommandType; // Assign the CommandType to a local variable CommandType
SQLCmd.CommandType := CmdType.Parse(CmdType.GetType(),'StoredProcedure'); // Parse out the Enumerated type of StoredProcedure0 -
I've done it using 'Microsoft ActiveX Data Objects 2.8 Library'.Command AUTOMATION
Code Below:
IF ISCLEAR(NADOConnection) THEN CREATE(NADOConnection);
NADOConnection.ConnectionString:='Driver={SQL Server};Server='+ServerName+';Database='+DatabaseName+';Uid='+USERID+';Pwd=xyz;';
NADOConnection.Open;
//Open command
IF ISCLEAR(NADOCommand) THEN
CREATE(NADOCommand);
lvarActiveConnection := NADOConnection;
NADOCommand.ActiveConnection := lvarActiveConnection;
NADOCommand.CommandText := 'SP_StockLedger';
NADOCommand.CommandType := 4;
NADOCommand.CommandTimeout := 0;
//lADOParameter:=NADOCommand.CreateParameter('@CompanyName', 200, 1, 30,COMPANYNAME);
//NADOCommand.Parameters.Append(lADOParameter);
NADOCommand.Execute;
IF ISCLEAR(NADORecordSet) THEN
CREATE(NADORecordSet);
NADORecordSet.ActiveConnection := lvarActiveConnection;
NADORecordSet.Open(NADOCommand);
WHILE NOT NADORecordSet.EOF DO BEGIN
// insert in temporary table
TempTable.INIT;
TempTable.INSERT;
NADORecordSet.MoveNext;
END;
//Close Connection
NADOConnection.Close;
CLEAR(NADOConnection);Sharad Gupta
Navision Technical Consultant & .Net Developer0 -
FYI, moving forward, it's not a recommend approach to use ActiveX or COM technology. Whereever possible you should implement integration components using the DotNet data type._________________
Niels-Henrik Sejthen
Senior Software Developer
Microsoft Dynamics NAV
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.0 -
Hi all,
I'm converting an old ADO call in a codeunit to use the new dotnet data type.
I can successfully call and execute my stored procedure, but I am having trouble trying to find the right syntax to get the value of my output parameter. I found Waldo's blog on the subject (using dotnet interop), but he never got around to example 3 (using an output parameter).
any tips? i have done some web searches and found examples in other languages. When i attempt to use a similar approach in NAV, it either does not work or will not compile.
I'm sure it is something relatively easy, i'm just not experienced enough with dotnet.
My legacy line of code that read the result of the output parameter:
sResult := FORMAT(ADOCommand.Parameters.Item('@Result').Value);
EDIT:
Embarrassed to say I got it to work. Must have had a typo upon an earlier attempt at the same thing:
sResult := FORMAT(SQLCommand.Parameters.Item('@Result').Value);kind of fell into this...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions