Linq to Sql and Decimal Data

Last post 11-07-2009 6:45 AM by nilsan. 1 replies.

Sort Posts:

  • Linq to Sql and Decimal Data

    11-07-2009, 3:51 AM
    • Participant
      1,599 point Participant
    • nilsan
    • Member since 12-30-2006, 5:43 AM
    • Ahmedabad
    • Posts 421

    Hello,
    I've used Linq to Sql (stored procedure) before but this time i found one problem.

    I've stored procedure like vi_User_Add below:

    ALTER PROCEDURE [dbo].[vi_User_Insert]
    (
    @useUserId int output,
    @useLoginName varchar(30), 
    @useFullName varchar(90), 
    @usePassword varchar(8), 
    @useGroupId int, 
    @useAccessTimeGroupId int, 
    @useActive bit, 
    @useMaximumLimit numeric(18,0), 
    @useWebAllowed bit, 
    @useEmployeeId int, 
    @UserID int,
    @ModuleID int,
    @mreturn_Value int output
    )
    AS 
    Begin Transaction 
    declare @KeyField varchar(100)
    declare @mUserId int
    INSERT INTO [vi_User]
    (
    [useLoginName] , 
    [useFullName] , 
    [usePassword] , 
    [useGroupId] , 
    [useAccessTimeGroupId] , 
    [useActive] , 
    [useMaximumLimit] , 
    [useCreatedDate] , 
    [useWebAllowed] , 
    [useEmployeeId]  
    ) VALUES 
    (
    @useLoginName , 
    @useFullName , 
    @usePassword , 
    @useGroupId , 
    @useAccessTimeGroupId , 
    @useActive , 
    @useMaximumLimit , 
    Getdate(), 
    @useWebAllowed , 
    @useEmployeeId  
    )
    
     SET @useUserId = CAST(SCOPE_IDENTITY() AS INT)
     SET @KeyField=@useLoginName + ',' + cast(@useGroupId as varchar(10)) + ',' + cast(@useAccessTimeGroupId as varchar(10))
     exec tr_ActivityLog_Add @useUserId,@ModuleId,'I',@KeyField
    
    If @@error <> 0 
    	begin	
    		rollback transaction
    		set @mreturn_Value = -1
    		return
    	end
    else
    	begin	
    		commit transaction
    		set @mreturn_value = 0
    		return
    	end


    I dropped this SP to my DBML file and it generated following code:

    <FunctionAttribute(Name:="dbo.vi_User_Insert")> _
        Public Function vi_User_Insert(<Parameter(DbType:="Int")> ByRef useUserId As System.Nullable(Of Integer), <Parameter(DbType:="VarChar(30)")> ByVal useLoginName As String, <Parameter(DbType:="VarChar(90)")> ByVal useFullName As String, <Parameter(DbType:="VarChar(8)")> ByVal usePassword As String, <Parameter(DbType:="Int")> ByVal useGroupId As System.Nullable(Of Integer), <Parameter(DbType:="Int")> ByVal useAccessTimeGroupId As System.Nullable(Of Integer), <Parameter(DbType:="Bit")> ByVal useActive As System.Nullable(Of Boolean), <Parameter(DbType:="Decimal")> ByVal useMaximumLimit As System.Nullable(Of Decimal), <Parameter(DbType:="Bit")> ByVal useWebAllowed As System.Nullable(Of Boolean), <Parameter(DbType:="Int")> ByVal useEmployeeId As System.Nullable(Of Integer), <Parameter(Name:="UserID", DbType:="Int")> ByVal userID As System.Nullable(Of Integer), <Parameter(Name:="ModuleID", DbType:="Int")> ByVal moduleID As System.Nullable(Of Integer), <Parameter(DbType:="Int")> ByRef mreturn_Value As System.Nullable(Of Integer)) As Integer
            Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo), useUserId, useLoginName, useFullName, usePassword, useGroupId, useAccessTimeGroupId, useActive, useMaximumLimit, useWebAllowed, useEmployeeId, userID, moduleID, mreturn_Value)
            useUserId = CType(result.GetParameterValue(0), System.Nullable(Of Integer))
            mreturn_Value = CType(result.GetParameterValue(12), System.Nullable(Of Integer))
            Return CType(result.ReturnValue, Integer)
        End Function


    <Parameter(DbType:="Decimal")> ByVal useMaximumLimit As System.Nullable(Of Decimal) : it converts any value to -1D
        
        Though before passing value to stored procedure i explicitly convert it to Decimal type like and in Web.config file i've set <globalization culture="en-GB"/>


    If txtMaxValLimit.Text = "" Then
                decMaxValLimit = 0
            Else
                decMaxValLimit = Convert.ToDecimal(txtMaxValLimit.Text.ToString())
    End If

    and then i pass it to the procedure like
            
             objvc.vi_User_Insert(userID, strLoginName, strFullName, strPassword, intGroup, intAccessTimeGroup, boolActive, boolWebAccess, decMaxValLimit, intEmpID, CInt(Session(USER_ID)), CInt(Session(MODULE_ID)), result)
            
             But it saves -1 for any value i enter. I don't understand what's the issue.
            
             Then i tried to insert with Ado.Net and it works perfectly fine.
            
             Has anyone encountered this problem before??

    Nilesh
    Please MARK POST AS AN ANSWER if it helps you
    My Blog
  • Re: Linq to Sql and Decimal Data

    11-07-2009, 6:45 AM
    • Participant
      1,599 point Participant
    • nilsan
    • Member since 12-30-2006, 5:43 AM
    • Ahmedabad
    • Posts 421

    Nobody has encountered problem like this..or any ideas what's making it -1D??

    Nilesh
    Please MARK POST AS AN ANSWER if it helps you
    My Blog
Page 1 of 1 (2 items)