I have a list box where the user can add choices depending on what items they want active in the database but I cannot figure out how loop through this listbox to update the items.

Any ideas?

Visual Studio 2010

Dim lstitem As String
            For i = 1 To ListBox1.Items.Count()
                lstitem = ListBox1.SelectedItem
                sql = "UPDATE laitemtype SET IsActive = 1 where itemtypedescription=@lst"
                Dim cmd6 As New SqlCommand(sql, Con)
                cmd6.Parameters.Add("@lst", SqlDbType.VarChar, 144)
                cmd6.Parameters("@lst").Value = lstitem
            Next i

Try it this way:

For i As Integer = 0 To ListBox1.Items.Count - 1
	Dim lstitem As String = ListBox1.SelectedItem.ToString()
	Dim sqlQuery As String = "UPDATE laitemtype SET IsActive = @active WHERE itemtypedescription=@lst"
	Dim cmd6 As New SqlCommand(sqlQuery, Con)
	'I hope oyu have created a new instance of SqlConnection AND Opened it!
	cmd6.Parameters.Add("@active", SqlDbType.Int).Value = 1
	cmd6.Parameters.Add("@lst", SqlDbType.VarChar, 144).Value = lstitem

moone009 now please mark the thread as Solved ;)