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
2
Answers
You don’t get to just make up methods or properties on the fly. The
Item
property that you’re getting here: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.
You can convert String to int by doing like this:
1.For C#:
int val = Int32.Parse("12");
2.For VB.NET:
Dim val as Integer = CInt("12")
Here you can find all Type Conversion Functions (Visual Basic).
https://msdn.microsoft.com/en-us/library/s2dy91zy.aspx
How to Convert a String to a Number (C# Programming Guide).
https://msdn.microsoft.com/en-us/library/bb397679.aspx