Home > Back-end >  ERROR - 'Conversion from string "" to type 'Integer' is not valid.'
ERROR - 'Conversion from string "" to type 'Integer' is not valid.'

Time:10-22

I am trying to enter data for each row into a SQL Database table but keep getting this error

'Conversion from string "VisitorID" to type 'Integer' is not valid.'

This is the code i have got

Dim url As String


        url = bcintegration.GetInfoForIntegration(DropDownList1.SelectedValue).Rows(0)(1)

        ServicePointManager.Expect100Continue = True
            ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
            Dim json As String = (New WebClient).DownloadString(url)
            IntegrationGridView.DataSource = JsonConvert.DeserializeObject(Of DataTable)(json)
            IntegrationGridView.DataBind()

        For Each row As GridViewRow In IntegrationGridView.Rows


            If DropDownList1.SelectedValue = "SignInSystemEntityIntegration" Then

THIS IS THE LINE WITH THE ERROR - bcintegration.SubmitDataForSignInSystemEntity(CInt(row.Cells("VisitorID").Text), Nothing, Nothing, Nothing, Nothing, Nothing, True, False, Nothing, Nothing, Nothing, 1)
            Else
            End If



        Next

The 'Nothing' statement is just for testing - that will have data later on.

Please Help

Thanks

CodePudding user response:

You don't get to just make up methods or properties on the fly. The Item property that you're getting here:

row.Cells("VisitorID")

only accepts an ordinal index, not a name. The documentation, which you should have read, tells you that and Intellisense would have told you that when you wrote the code. The error message is also telling you that. You need to provide a column index, not a column name.

CodePudding user response:

The cell seems to contain a value that can't be parsed to an int.

I would suggest using :

If Integer.TryParse(row.Cells("VisitorID").Text, visitorId) Then
  'Continue your code here
 bcintegration.SubmitDataForSignInSystemEntity(visitorId, Nothing, Nothing, Nothing, Nothing, Nothing, True, False, Nothing, Nothing, Nothing, 1)
Else
  'Cant continue because the value is invalid
End If
  • Related