13: Failed to convert parameter value from a Sting to a Int32. RRS feed

  • General discussion

  • I have the following code...

            Dim AdMgtID As Integer
            Dim TotalAds As String
            Dim Ad1 As String
            Dim AdCheck As Integer
            Dim IndexLoop As Integer

            Dim AdText As String = ""
            Dim ReplyText As String
            Dim StartDate As Date
            Dim EndDate As Date
            Dim NoofPlays As Integer
            Dim Counter As Integer
            Dim Priority As Integer
            Dim ModifiedDate As Date
            Dim Retired As Date
            Dim AreaCode As Char
            Dim Prefix As Char
            Dim AdEvent As String

            Me.ReferralDataSet.EnforceConstraints = False

            TotalAds = Me.ReferralDataSet.sp_Admgt_Select.Count

            For IndexLoop = 0 To TotalAds - 1
                AdMgtID = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("AdMgtID")
                AdText = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("AdText")

                If IsDBNull(Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("ReplyText")) Then
                    ReplyText = ""
                    ReplyText = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("ReplyText")
                End If
                StartDate = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("StartDate")
                EndDate = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("EndDate")
                NoofPlays = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("NoofPlays")
                Counter = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Counter")
                Priority = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Priority")

                If IsDBNull(Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Retired")) Then
                    Retired = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Retired")
                End If

                If IsDBNull(Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("AreaCode")) Then
                    AreaCode = ""
                    AreaCode = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("AreaCode")
                End If

                If IsDBNull(Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Prefix")) Then
                    Prefix = ""
                    Prefix = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Prefix")
                End If

                If IsDBNull(Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Event")) Then
                    AdEvent = ""
                    AdEvent = Me.ReferralDataSet.sp_Admgt_Select.Rows(IndexLoop).Item("Event")
                End If

                If AdMgtID = 1 Then
                    ModifiedDate = Now()
                    Counter = Counter + 1


                    ''Me.AdmgtDataAdapter.UpdateCommand.Parameters("@MODIFIED").Value = ModifiedDate
                    Me.AdmgtDataAdapter.UpdateCommand.Parameters("@COUNTER").Value = Counter



                    Exit For

                End If

    When I Execute the Query I get the following error:
    13: Failed to convert parameter value from a Sting to a Int32.

    I have the Counter parameter defined everywhere as an Int.

    What am I missing?


    Friday, August 29, 2008 9:55 PM

All replies

  •  For IndexLoop = 0 To TotalAds - 1

    TotalAds is dim'med as a String on the second line and here you are subtracting one. It is very strongly encouraged that you go to your Project properties->Compile and set "Optino strict:" to on. You will see many errors pop up once you do this and you will have to go through and correctly cast/convert variables. It will force you to code better, and, you will also avoid most errors like the one you have above. Since you dim'med TotalAds as a String, you will not be able to assign me.ReferralDataSet.sp_Admgt_Select.Count to it because Count returns in int. I don't know the size of your application or the demand it could potentially place on performance, but your code will also be more optimized with that Option Strict set to on.
    "Nothing Ventured, Nothing Gained"
    Friday, August 29, 2008 11:58 PM
  • Thank you for the hint...I am still learning VB and didn't write the original application. Turning that on shows a lot of errors now so I'll have to determine how to proceed. However, changing the TotalAds to an Integer made no difference. I'll keep looking for an answer.
    Tuesday, September 2, 2008 1:53 PM
  • Which line raises the error? If you add a breakpoint to step through the code snippet to see whether you can get the more information about the code. 
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, September 3, 2008 12:37 PM