Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling SProc that Returns output Parameters
Message
De
11/07/2005 19:13:48
 
 
À
11/07/2005 18:56:01
John Darragh
Entrotech Engineering, Inc.
Torrance, Californie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01030503
Message ID:
01031431
Vues:
30
Sorry I sent you down the wrong path, John. I had thought you had said that your Stored Proc used output parameters, not a return value.

I don't use MM, so maybe I shouldn't have answered your question, but it seemed like a simple thing. I'm glad you finally got it figured out though ... without my help! =)

~~Bonnie




>There isn't a method called ExecuteNonQuery on the mmBusinessObject class, but there is one called ExecNonQuery, which, in turn calls ExecNonQuery on the mmDataAccessBase, which calls the method ExecuteNonQuery on a SqlCommand object. It took quite a lot of debugging to figure out, but I was able to find the root of the problem.
>
>The problem is that the SqlCommand objects that work with stored procedures treat return values as if they were mandatory procedure arguments. Since the procedure I was using had a return value, the SqlCommand object was expecting an additional Parameter with it's direction set to ParameterDirection.ReturnValue, but when it failed, the message wasn't very helpful in figuring out that this was the cause of the problem.
>
>The corrected code is (the difference is the two lines setting up the retVal return value as if it were a procedure parameter):
>
>
>Protected Overrides Sub HookSetDefaultValues(ByVal dataRow As System.Data.DataRow)
>        Dim cmd As IDbCommand
>        Dim sValue As String
>
>        If Not (Me.DefaultValues Is Nothing) Then
>            ' Cast the DefaultValues object to the custom type
>            Dim Defaults As ContactDefaultValues = CType(Me.DefaultValues, ContactDefaultValues)
>
>            ' Store the default values in the new DataRow
>            dataRow("idEntityType") = Defaults.idEntityType
>            dataRow("idMaritalStatus") = Defaults.idMaritalStatus
>
>            '' Go to the database to get the new contact's sRefNum
>            '' This way, the user knows the Ref Num before the contact is saved at all.
>            Dim retVal As IDbDataParameter = Me.CreateParameter("@nRetVal", 1)
>            retVal.Direction = ParameterDirection.ReturnValue
>            Dim param1 As IDbDataParameter = Me.CreateParameter("@idSeqType", 4)
>            Dim param2 As IDbDataParameter = Me.CreateParameter("@idContact", 1)
>            Dim param3 As IDbDataParameter = Me.CreateParameter("@sValue", "dummyvalue")
>            param3.Direction = ParameterDirection.InputOutput
>            Dim params() As IDbDataParameter = {param1, param2, param3}
>
>            Me.ExecSprocScalar("CalcSeqNum", cmd, params)
>
>            sValue = cmd.Parameters("@sValue").value.ToString
>            dataRow("sRefNum") = sValue
>
>        End If
>
>    End Sub
>
>
>
>Bonnie's suggestion also works, though the mmBusinessObject.ExecNonQuery method sets up the underlying SqlCommand with type Command.Text, so you have to work around this limitation by extracting and manipulating the SqlCommand object from the mmDataAccessBase class, or figuring out what the syntax would be for specifying the CommandText for a command of type Command.Text such that it would hanlde return parameters correctly (good luck with that!).
>
>Hope this saves someone else from some grief!
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform