Reputation: 95
I have a simple loop I am trying to use to capture data from a form and put it in to a stored procedure that updates a table. It seems to me like it should do what it's supposed to do, but I'm getting a conversion error and I'm not really sure why. I don't even know if it does in fact work since I'm getting an error that doesn't make a lot of sense to me. Here's what I have currently:
Dim rowcounter As Integer = 1
While rowcounter < 15
Dim NameHolder As String = "LineID" + rowcounter.ToString
CMD.CommandTimeout = 60
CMD.Connection = CONN
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "UpdateArchived"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@ID", Me.Controls(NameHolder).ToString)
DA.SelectCommand = CMD
DS.Clear()
DA.Fill(DS)
End While
The error is with the Me.Controls(NameHolder).ToString line. It says the following: Conversion from string "LineID1" to type 'Integer' is not valid.
What is being converted to an integer here? Does Me.Control return the control as an integer?
Upvotes: 1
Views: 250
Reputation:
Try using & not +
Both are concat operators but + will try and add an integer to an integer, hence the error. & only deals with strings.
So..
Dim NameHolder As String = "LineID" & rowcounter.ToString
HTH
Upvotes: 1