[2005] unable to delete information from database - using listview
i want to delete the information from the db but it wont work. this r my codes:
[Highlight=VB]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\temp\db1.mdb"
Dim con As OleDb.OleDbConnection
' Dim dr As OleDb.OleDbDataReader
Dim cmd As New OleDb.OleDbCommand
Try
Dim strselect As String = "Delete from item where DateDeleted ='" & Format(DateTimePicker1.Text) & "'"
'create a new connection
con = New OleDb.OleDbConnection(strcon)
con.Open()
cmd.Connection = con
cmd.CommandText = strselect
cmd.ExecuteNonQuery()
con.Close()
'If dr.Read Then
'TextBox2.Text = dr("ItemId")
'TextBox1.Text = dr("ReferenceNo")
'cbxtype.Text = dr("ItemCategory")
'DateTimePicker1.Text = dr("DateDeleted")
'End If
'dr.Close()
Catch ex As Exception
MessageBox.Show("The record is deleted")
End Try
' Dim alvw As ListView.SelectedIndexCollection = lvfine.SelectedIndices
' For Each lvw As Integer In alvw
'lvfine.Items.RemoveAt(lvw) ' Remove them from the list view.
' Next
For i As Integer = Me.lvfine.SelectedItems.Count - 1 To 0 Step -1
Me.lvfine.Items.Remove(Me.lvfine.SelectedItems(i))
Next i
For i As Integer = Me.lvfine.SelectedIndices.Count - 1 To 0 Step -1
Me.lvfine.Items.RemoveAt(Me.lvfine.SelectedIndices(i))
Next i
While Me.lvfine.SelectedItems.Count > 0
Me.lvfine.Items.Remove(Me.lvfine.SelectedItems(0))
End While
' Try
'Dim strselect As String = "Insert into item(DateDeleted) values('" & Format(DateTimePicker1.Value) & "')"
'create a new connection
'con = New OleDb.OleDbConnection(strcon)
'con.Open()
'cmd.Connection = con
'cmd.CommandText = strselect
'dr = cmd.ExecuteReader
'If dr.Read Then
'TextBox2.Text = dr("ItemId")
'TextBox1.Text = dr("ReferenceNo")
'cbxtype.Text = dr("ItemCategory")
' DateTimePicker1.Text = dr("DateDeleted")
'End If
'dr.Close()
'Catch ex As Exception
' MessageBox.Show("The record is deleted")
' End Try
End Sub
/VBCODE]
Re: [2005] unable to delete information from database - using listview
Is this a joke? This is your fourth thread on the same topic, even after I specifically pointed out in the third thread that you shouldn't be creating duplicates. If this is a plan to raise my blood pressure it's working fantastically.