SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member Aina's Avatar
    Join Date
    Aug 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy failed to convert parameter value from a string to a int32

    I am not sure where my app is failing but most probably this is where it is failing.. I think lblExpID.Text is the culprit. Here's the relvant part of my code:
    Dim lblExpID As Label
    For Each item In LSGrid.Rows
    lblExpID = item.FindControl("lblID")

    If txtExpGenFund.Text <> "" Then
    sqlArray(i) = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _
    Val(txtExpGenFund.Text) & "," & Val(txtExpDetSpecialRevenue.Text) & "," & _
    Val(txtExpDetCapitalProjects.Text) & "," & expTotal & "," & reportingYear & "," & "Test Comments" & "," & UserID
    End If

    Can u help me identify why i am getting this error looking at the sp below:
    PROCEDURE [dbo].[uspEXPENDITURE_DETAILS]
    (
    @ExpDetailsID int=0 output,
    @ExpDet_ExpID int,
    @ExpDet_Municipality_ID nvarchar(50),
    @ExpDetGeneralFund money,
    @ExpDetSpecialRevenue money,
    @ExpDetCapitalProjects money,
    @ExpDetTotal money,
    @Exp_Reporting_Year varchar(10),
    @ExpComments varchar(max),
    @Contact_ID int

    )

    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    delete from [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Exp_Reporting_Year=@Exp_Reporting_Year

    If @ExpDetailsID >= 0
    Begin

    INSERT INTO [dbo].[TBL_EXPENDITURE_DETAILS]
    ([ExpDet_ExpID]
    ,[ExpDet_Municipality_ID]
    ,[ExpDetGeneralFund]
    ,[ExpDetSpecialRevenue]
    ,[ExpDetCapitalProjects]
    ,[ExpDetTotal]
    ,[Exp_Reporting_Year]
    ,[ExpComments]
    ,[ExpDetCreatedBy]
    ,[ExpDetCreateDate])
    VALUES
    (@ExpDet_ExpID,
    @ExpDet_Municipality_ID,
    @ExpDetGeneralFund,
    @ExpDetSpecialRevenue,
    @ExpDetCapitalProjects,
    @ExpDetTotal,
    @Exp_Reporting_Year,
    @ExpComments,
    @Contact_ID,
    GetDate()

    )

    SET @ExpDetailsID = SCOPE_IDENTITY()
    return @ExpDetailsID

    end

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is this VB Script (ASP)? Might want to move it to the classic ASP Forum. Then again, I don't use VB.NET, just looks different.

  3. #3
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it give you a line number? In my experience a stored procedure error is typically not that specific; I usually get "Something went screwy" and you dig a little deeper and find that it probably is a problem down in the stored proc. So by the error message you're getting, I would actually suspect that the problem is in a line of the program code. Possibly sneaky one where you've implicitly passed a string that looks like an int to another variable.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  4. #4
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Jersey
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ExpDet_ExpID is an integer in your stored procedure, you need to parse lblExpID.Text before you pass it into the query.

    Code:
    Int32.Parse(lblExpID.Text)
    Matt Daly

  5. #5
    SitePoint Member JamieTownsend's Avatar
    Join Date
    Aug 2010
    Location
    Cheltenham, UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do not use parse as it will return an exception if fails.

    use something like this:

    int iExpId;
    if (Int32.TryParse(lblExpID.Text, out iExpId))
    {
    // valid int
    }

    else
    // fail or do something else

  6. #6
    SitePoint Member Aina's Avatar
    Join Date
    Aug 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing is working so far..i have tried everything..please help.. I need to submit this day after tomorrow:-(

  7. #7
    SitePoint Member Aina's Avatar
    Join Date
    Aug 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is VB.NET. I am using VS framework 3.5

  8. #8
    SitePoint Member JamieTownsend's Avatar
    Join Date
    Aug 2010
    Location
    Cheltenham, UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, for starters, if lblExpID.Text fails in it's conversion to Int what do you want to happen ?

    My reply still stands for converting to Int, VB would be something like:

    Dim iExpId As Integer
    If (Int32.TryParse(lblExpID.Text, iExpId)) Then
    // valid int
    Else
    // invalid int
    End If

  9. #9
    SitePoint Member Aina's Avatar
    Join Date
    Aug 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YOU R THE BEST Jamie. Ya it worked. Three cheers to you...:-)

  10. #10
    SitePoint Member JamieTownsend's Avatar
    Join Date
    Aug 2010
    Location
    Cheltenham, UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad it worked

  11. #11
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    As far as I recall, with VB you can concat string and ints into a single string without converting. I could be wrong though so don't take it for granted. Anyway, the result of &ing things together like that will be a string.

    Part of the problem in us helping is that we aren't seeing all the code or how it's being used in conjunction with the stored proc. I am assuming this bit is in a loop to incremement the index "i"? Anyway, since you're assigning a long concatenated string to that array index, try setting it to a value first, and either put a watch, or beakpoint on it to see if that's where the error actually is.

    Dim testVal as String

    testVal = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _ ' plus the rest
    sqlArray(i) = testVal ' set break here and inspect testVal

    If it makes it there without causing an exception, and testVal has the right value, then the error is somewhere else.

    I fyour intent is to collect params for the stored proc, then you probably need to use a multidimensional array and set each element to a specific value. It looks like you're hoping the commas you're including will be enough to delimit params.

    for r = 0 to rowCount step 1

    sqlArray(r, ID1_INDEX) = id1
    sqlArray(r, ID2_INDEX) = TextBox1.Text
    ' and so one, loop through the rows, and use consts to define your param indexes.

    end for

    My VB syntax might be a bit off, it's been about 5 years since I've touched it. And if my hunches here are wrong also, just disregard the post.

  12. #12
    SitePoint Member Aina's Avatar
    Join Date
    Aug 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    GOT MY REPLY.. please follow JamieTownsend answers if you have similar issue


    Quote Originally Posted by Aina View Post
    I am not sure where my app is failing but most probably this is where it is failing.. I think lblExpID.Text is the culprit. Here's the relvant part of my code:
    Dim lblExpID As Label
    For Each item In LSGrid.Rows
    lblExpID = item.FindControl("lblID")

    If txtExpGenFund.Text <> "" Then
    sqlArray(i) = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _
    Val(txtExpGenFund.Text) & "," & Val(txtExpDetSpecialRevenue.Text) & "," & _
    Val(txtExpDetCapitalProjects.Text) & "," & expTotal & "," & reportingYear & "," & "Test Comments" & "," & UserID
    End If

    Can u help me identify why i am getting this error looking at the sp below:
    PROCEDURE [dbo].[uspEXPENDITURE_DETAILS]
    (
    @ExpDetailsID int=0 output,
    @ExpDet_ExpID int,
    @ExpDet_Municipality_ID nvarchar(50),
    @ExpDetGeneralFund money,
    @ExpDetSpecialRevenue money,
    @ExpDetCapitalProjects money,
    @ExpDetTotal money,
    @Exp_Reporting_Year varchar(10),
    @ExpComments varchar(max),
    @Contact_ID int

    )

    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    delete from [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Exp_Reporting_Year=@Exp_Reporting_Year

    If @ExpDetailsID >= 0
    Begin

    INSERT INTO [dbo].[TBL_EXPENDITURE_DETAILS]
    ([ExpDet_ExpID]
    ,[ExpDet_Municipality_ID]
    ,[ExpDetGeneralFund]
    ,[ExpDetSpecialRevenue]
    ,[ExpDetCapitalProjects]
    ,[ExpDetTotal]
    ,[Exp_Reporting_Year]
    ,[ExpComments]
    ,[ExpDetCreatedBy]
    ,[ExpDetCreateDate])
    VALUES
    (@ExpDet_ExpID,
    @ExpDet_Municipality_ID,
    @ExpDetGeneralFund,
    @ExpDetSpecialRevenue,
    @ExpDetCapitalProjects,
    @ExpDetTotal,
    @Exp_Reporting_Year,
    @ExpComments,
    @Contact_ID,
    GetDate()

    )

    SET @ExpDetailsID = SCOPE_IDENTITY()
    return @ExpDetailsID

    end

  13. #13
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Odd, the two posts above mine weren't showing when I posted. Glad you got it worked out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •