RobLife
RobLife

Reputation: 95

Looping through textbox contorls in vb.net to push data into a table

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

Answers (1)

user2672288
user2672288

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

Related Questions