C
Co
Hi All,
I'm trying to delete multiple files from a database but get an error
sayong deleted row information cannot be accessed through the row.
First I get all the selected files and their IDs.
Case "Delete"
Select Case MsgBox("Bestand Verwijderen..." & _
Microsoft.VisualBasic.ControlChars.Cr & _
"Wil je dit bestand echt
verwijderen?", MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation,
"Verwijderen")
Case MsgBoxResult.Yes
Dim j As Integer
Dim s As Integer
s = ListView.SelectedItems.Count
Dim aDelFiles(s) As String
For j = 0 To ListView.SelectedItems.Count - 1
aDelFiles(j) = ListView.SelectedItems
(j).Tag
Next
DelFiles(aDelFiles)
Case MsgBoxResult.Cancel
End Select
Then the sub DelFiles will have to do the actual deleting:
Private Sub DelFiles(ByVal aFiles2Delete() As String)
'this code will delete the name of a folder
Dim sql As String = "SELECT * FROM Bestanden"
Dim strTable As String = "Bestanden"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim i As Integer
Dim dr As DataRow
conn.Open()
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
For i = 0 To aFiles2Delete.Length - 1
For Each dr In ds.Tables(0).Rows
If dr.Item("Id") = aFiles2Delete(i) Then
ds.Tables(strTable).Rows(0).Delete()
End If
Next
Next
'sent the updated dataSet to the database
da.Update(ds, strTable)
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
There I get the Exception thrown with the mentioned error message.
Marco
The Netherlands
I'm trying to delete multiple files from a database but get an error
sayong deleted row information cannot be accessed through the row.
First I get all the selected files and their IDs.
Case "Delete"
Select Case MsgBox("Bestand Verwijderen..." & _
Microsoft.VisualBasic.ControlChars.Cr & _
"Wil je dit bestand echt
verwijderen?", MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation,
"Verwijderen")
Case MsgBoxResult.Yes
Dim j As Integer
Dim s As Integer
s = ListView.SelectedItems.Count
Dim aDelFiles(s) As String
For j = 0 To ListView.SelectedItems.Count - 1
aDelFiles(j) = ListView.SelectedItems
(j).Tag
Next
DelFiles(aDelFiles)
Case MsgBoxResult.Cancel
End Select
Then the sub DelFiles will have to do the actual deleting:
Private Sub DelFiles(ByVal aFiles2Delete() As String)
'this code will delete the name of a folder
Dim sql As String = "SELECT * FROM Bestanden"
Dim strTable As String = "Bestanden"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim i As Integer
Dim dr As DataRow
conn.Open()
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
For i = 0 To aFiles2Delete.Length - 1
For Each dr In ds.Tables(0).Rows
If dr.Item("Id") = aFiles2Delete(i) Then
ds.Tables(strTable).Rows(0).Delete()
End If
Next
Next
'sent the updated dataSet to the database
da.Update(ds, strTable)
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
There I get the Exception thrown with the mentioned error message.
Marco
The Netherlands