|
-
Aug 3rd, 2006, 02:40 AM
#1
Thread Starter
Member
[2005] Deleting a selected item from a ListView and Access database
here r my codes
wat shud i do if i want the selected item in the listview to be deleted in both the listview and the database?? can someone help me with the codeS???
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|