locked
Stored procedure with result RRS feed

  • Question

  • I have a simple stored procedure that I am executing and just want to get the result of the stored procedure.  0 if successful otherwise the error code.  I read the article saying set the result in the inserting event but not sure what needs to be set.  Can someone help?  Below is a snippet of my code. 

     Using command = New SqlCommand(procedure, connection)

                        command.CommandType = CommandType.StoredProcedure

                        command.Parameters.Add(

                            New SqlParameter("@DataDomainID", entity.DataDomainID))

                        command.Parameters.Add(

                            New SqlParameter("@SourceTableID", entity.SourceTableID))

                        connection.Open()

                        command.ExecuteNonQuery()


    • Edited by Russ356 Wednesday, March 23, 2016 1:14 PM
    Wednesday, March 23, 2016 1:14 PM

Answers

  • Hi Russ356,

    >> 0 if successful otherwise the error code

    Do you mean if the stored procedure successful, it will return 0, otherwise, it will return an error code?

    Please refer to below articles which introduce how to execute a Stored Procedure in the inserting event. Hope that can help you. You can try the sample in that article first and then replace your stored procedure. If any questions, please feel free to come back.

    https://msdn.microsoft.com/en-us/library/jj635144.aspx?f=255&MSPPError=-2147217396

    The connect string name you can find it in Web.config under the connectStrings node.

    <connectionStrings>
        <add name="_IntrinsicData" connectionString="Data Source=|SqlExpressInstanceName|;AttachDbFilename=|ApplicationDatabasePath|;Integrated Security=True;Connect Timeout=30;MultipleActiveResultSets=True" />
        <add name="7dd2326c-36f4-424c-962d-84fc0f9ca1ee" connectionString="Service Url=http://localhost:29935/Microsoft.LightSwitch.SecurityData.svc;Is Windows Authentication=False;User Name=Administrator;Password=username;Allow Invalid Certificate=False" />
      </connectionStrings>

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, April 5, 2016 8:16 AM
    • Marked as answer by Angie Xu Tuesday, April 5, 2016 8:16 AM
    Monday, March 28, 2016 8:13 AM
    Moderator