Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...DAL/BL and handling Output ParametersDAL/BL and handling Output Parameters
Previous
 
Next
New Post
3/26/2010 3:35 PM
 

Hi,

I have a stored procedure that returns an output parameter (Claim ID) after a new row is entered. I need to use this output later on so I am trying to store it in a hidden field. I originally did this through a function temporarily so I could see how things worked and try to figure out how to do it using the DAL/BL of DNN.

My Original test function went something like this: (edited for length)

    Public Shared Function InsertMMSPreClaim(ByVal Adjuster_ID As Integer, ByVal Client_ID As Integer, ByVal LocationCode As String, _
                                                 ByVal DateOfLoss As DateTime, ByVal TimeOfLoss As String, ByVal DateEntered As DateTime, _
                                                 ...) As Integer
        Dim preClaimID As Integer
        Dim myConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("connection").ConnectionString)
        myConn.Open()
        Dim myCommand As New SqlCommand("InsertInformation", myConn)
        myCommand.CommandType = CommandType.StoredProcedure

        Dim preClaimIDParam As New SqlParameter("@prmPreClaimID", SqlDbType.Int)
        preClaimIDParam.Direction = ParameterDirection.Output

        myCommand.Parameters.Add(New SqlParameter("@prmUser_ID", SqlDbType.Int))
        myCommand.Parameters("@prmUser_ID").Value = Adjuster_ID
        .

        .

        .
        myCommand.Parameters.Add(New SqlParameter("@prmLocationCode", SqlDbType.NVarChar))
        myCommand.Parameters("@prmLocationCode").Value = LocationCode


        myCommand.Parameters.Add(preClaimIDParam)
        Dim reader As SqlDataReader = myCommand.ExecuteReader()

        preClaimID = Convert.ToInt32(preClaimIDParam.Value)

        Return preClaimID
    End Function

 

This function worked great, returned the value correctly and everything. I then tried to move this to using the DataProvider/SqlDataProvider in DNN. I made some changes that I thought were correct and when I enter the data, it always returns 0 as the output number. Does anyone know what I am doing wrong here? (Note: I took out a whole bunch of parameters to reduce the size of the code, but I dont think that should make a difference to the errors I am having, If you need all of the code let me know.)

Stored Procedure

    INSERT INTO dbo.PreClaimTable
        (Adjuster_ID, Client_ID,  LostTime, LostTimeDays)
    VALUES
        (@prmUser_ID, @prmClient_ID, @prmLostTime, @prmLostTimeDays)

    set @PreClaimID =  SCOPE_IDENTITY()
    SELECT @prmPreClaimID = @PreClaimID
    RETURN @PreClaimID

Controller.vb

        Public Function AddMedicalManagement(ByVal objMedicalManagement As MedicalManagementInfo) As Integer

            DataProvider.Instance().AddMedicalManagement(objMedicalManagement.Adjuster_ID, objMedicalManagement.Client_ID, _
                                                         objMedicalManagement.LostTime, objMedicalManagement.LostTimeDays)

        End Function

Data Provider

        Public MustOverride Function AddMedicalManagement(ByVal Adjuster_ID As Integer, ByVal Client_ID As Integer,  ByVal LostTime As String, _
                                                     ByVal LostTimeDays As String) As Integer

SQLDataProvider

        Public Overrides Function AddMedicalManagement(ByVal Adjuster_ID As Integer, ByVal Client_ID As Integer,  ByVal LostTime As String, _
                                                     ByVal LostTimeDays As String) As Integer
            Dim sqlOutputParameter = New SqlParameter("@prmPreClaimID", SqlDbType.Int)
            sqlOutputParameter.Direction = ParameterDirection.Output
            Dim preClaimID As Integer
            SqlHelper.ExecuteReader(claimsConnectionString, "spInsertMMSPreClaimInfo", Adjuster_ID, Client_ID,  LostTime, LostTimeDays, sqlOutputParameter)
            preClaimID = Convert.ToInt32(sqlOutputParameter.Value)
            Return preClaimID
        End Function

 

 

 

 
New Post
4/7/2010 8:57 AM
 
Anyone have any ideas that might put me on the right track? I still cant get this working. Thanks, Chris
 
New Post
4/7/2010 10:16 AM
 

Chris,

You may want to alter the procedure call by removing the output parameter and just returning a value (via RETURN value)  - since they are the same from your example. Use the SQLHelper.ExecuteScalar function to return the value.  Most tof the Add functions (eg. AddTab) use this method.

Paul.

 
New Post
4/7/2010 2:54 PM
 

Hi Paul,

I made some changes per your suggestion, the SqlDataProvider is now:

 

Public Overrides Function AddMedicalManagement(ByVal Adjuster_ID As Integer, ByVal Client_ID As Integer,  ByVal LostTime As String, _
                                                     ByVal LostTimeDays As String) As Integer

            Return CType(SqlHelper.ExecuteScalar(claimsConnectionString, "spInsertMMSPreClaimInfo", Adjuster_ID, Client_ID, , LostTime, LostTimeDays), Integer)

 

the stored procedure is now:

USE [Claims]
GO
/****** Object:  StoredProcedure [dbo].[spInsertMMSPreClaimInfo]    Script Date: 04/07/2010 14:11:32 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER Procedure [dbo].[spInsertMMSPreClaimInfo]

    @prmUser_ID        int,
    @prmClient_ID    int,
    @prmLostTime        nvarchar(50),
    @prmLostTimeDays        nvarchar(50)

As
SET NOCOUNT ON
DECLARE @PreClaimID int
    -- Insert values into PreClaimTable
    INSERT INTO dbo.PreClaimTable
        (Adjuster_ID, Client_ID,  LostTime, LostTimeDays)
    VALUES
        (@prmUser_ID, @prmClient_ID,  @prmLostTime, @prmLostTimeDays)

    set @PreClaimID =  SCOPE_IDENTITY()
    Select @PreClaimID

 

Everything inserts fine, but no matter what I do I am always getting a 0 as my PreClaimID. Any Idea why this might be occuring?

Thanks again for your help.

Chris

 
New Post
4/7/2010 3:28 PM
 

Chris,

Change the last line of the store procedure from "Select @PreClaimID" to "Return @PreClaimID" and all should work.

Paul.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...DAL/BL and handling Output ParametersDAL/BL and handling Output Parameters


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out