Results 1 to 2 of 2

Thread: [2005] unable to delete information from database - using listview

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    58

    [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]

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width