Can someone please help me figure out what I am doing wrong here? It is supposed to find the checkboxes per dataitem and see if that specific dataitem needs to be deleted. And if it does, to delete them all after adding it to one SQL statement. Please look below and give me insight!
Sub btnDelete_click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DeleteMe As Boolean
Dim anItem As DataListItem
Dim i As Integer = 0
Dim strDeleted As String = "('"
Dim SQLString As String = "DELETE FROM Photos WHERE PhotoID IN "
For Each anItem In dlAlbumPhotos.Items
DeleteMe = CType(anItem.FindControl("chkDelete"), CheckBox).Checked
If DeleteMe Then
i += 1
if i = 1 then
SQLString &= "('" & anItem.ItemIndex
strDeleted &= anItem.ItemIndex
else
SQLString &= "', '" & anItem.ItemIndex
strDeleted &= "', '" & anItem.ItemIndex
end if
Dim strDelName As String = anItem.ItemIndex
Dim filepath As String = Server.MapPath("\") & "\Vegas2\Galleries\NL" & MakeInt(Trim(Request.QueryString("album"))) & "\"
if File.Exists(filePath & strDelName & ".jpg") then file.delete(filePath & strDelName & ".jpg")
if File.Exists(filePath & "T_" & strDelName & ".jpg") then file.delete(filePath & "T_" & strDelName & ".jpg")
End if
Next
dlAlbumPhotos.DataBind()
strDeleted &= "')"
SQLString &= "')"
if i > 0 then
Dim conDelete As OdbcConnection
Dim cmdSelect As OdbcCommand
conDelete = New OdbcConnection( System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") )
cmdSelect = New OdbcCommand( SQLString, conDelete )
conDelete.Open()
cmdSelect.ExecuteNonQuery()
conDelete.Close()
lblDeletion.Visible = True
lblDeletion.Text = "<br />Successfully deleted pictures " & strDeleted & "."
end if
End Sub