Context using SP doesn't return value

Context using SP doesn't return value

Postby Zero-G. » Sat 13 Nov 2010 10:26


Using the latest version of LinQConnect for mySQL (rel. date Nov. 2010)

In my DataContext, there I use a SP with a return value. The generated code looks like:
Code: Select all
        ''' There are no comments for Rechnungvergeben in the schema.

        Public Function Rechnungvergeben( Uebergabeid As String, Isbezahlt As System.Nullable(Of Short), Zahlungsart As String, Kundenname As String, Kundenadresse As String, Auftragsbetrag As System.Nullable(Of Decimal), Bezahlterbetrag As System.Nullable(Of Decimal), Mitarbeitername As String, Fid As System.Nullable(Of Long), Rnr As System.Nullable(Of Integer), Auftragsjahr As System.Nullable(Of System.DateTime), ByRef Nrenummer As System.Nullable(Of Integer)) As System.Int32
            Dim res As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod(), MethodInfo), Uebergabeid, Isbezahlt, Zahlungsart, Kundenname, Kundenadresse, Auftragsbetrag, Bezahlterbetrag, Mitarbeitername, Fid, Rnr, Auftragsjahr, Nothing)
            Nrenummer = CType(res.GetParameterValue(11), System.Nullable(Of Integer))
            Return CType(res.ReturnValue, System.Int32)
        End Function

The problem is, that the returned value is always = 0

When I change the last codelines to:
Code: Select all
Nrenummer = CType(res.GetParameterValue(11), System.Nullable(Of Integer))
            Return CType(Nrenummer, System.Int32)
        End Function

Then everything works fine. - Please check this out and tell me the results

Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby StanislavK » Mon 15 Nov 2010 17:28

Could you please specify the definition of this stored procedure? As far as I can understand, Nrenummer is an out parameter, not the return value. Am I correct? In this case, Nrenummer should not be returned by the Rechnungvergeben method, at least because the procedure may have several out parameters. To get Nrenummer, please use the argument of the Rechnungvergeben method that corresponds to the out parameter. For example, if you have a stored procedure
Code: Select all
CREATE DEFINER = 'root'@'%'
PROCEDURE test_proc(IN a INT, IN b INT, OUT output INT)
  SET output = a+b;

and the generated method is
Code: Select all
Public Function TestProc( A As System.Nullable(Of Integer), B As System.Nullable(Of Integer), ByRef Output As System.Nullable(Of Integer)) As System.Int32

you can get the out parameter as follows:
Code: Select all
Dim MyDataContext As New TestDataContext
Dim res As Integer?
MyDataContext.TestProc(2, 3, res)

After TestProc is executed, 'res' will contain the value of the output parameter.

Please tell us if this helps.
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Return to LinqConnect (LINQ to SQL support)