Experts, I'm using ASP.NET, VB, MS SQL Server, Repeater Control
I am trying to update multiple records in a repeater control.
This is for a content management page. I have a list of "page sections" for any given page. They are listed via the repeater control. I want to give the admin the ability to sort the page sections. To this end, I have a textbox that binds to the sectionOrder row of the database for each page section. This works fine.
I want the user to be able to change the numeric values of the sectionOrder textboxes and click one button to update all records.
I think I am close, but I am receiving an error "Conversion failed when converting the varchar value 'secID' to data type int." Currently, the secID is pulling it's value from a HiddenField value that binds to the ID (primary key) of each repeater item.
Please take a look at my attached code. I have never tried to do an UPDATE using a repeater control (so that code may be questionable as well), much less trying to update multiple records at once. Thank you VERY much for taking a look at this.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim secID As Integer
Dim secOrder As String
Dim connStr As String = ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
Dim sql As String
Dim conSql As SqlConnection
conSql = New SqlConnection(connStr)
Dim regUpdateCmd As New SqlCommand(sql, conSql)
For Each ri As RepeaterItem In Repeater1.Items
secID = CType(ri.FindControl("Hiddenfield1"), HiddenField).Value
secOrder = CType(ri.FindControl("TxtSectionOrder"), TextBox).ToString
sql = "UPDATE mwcPages_Sections SET sectionOrder = 'secOrder' WHERE sectionID = 'secID'"
regUpdateCmd.CommandText = sql