listview如何删除数据库中的数据

时间:2013-10-18 03:46:15

标签: vb.net visual-studio-2010 listview

我在listview中删除数据时遇到问题,我能够删除listview选择记录中的数据,但是数据库中没有删除所选数据,我有一个源代码

Private _updateinputalltrans As Boolean

Private Sub btndelete_Click(sender As System.Object, e As System.EventArgs) Handles btndelete.Click
        With Me.listviewpos.SelectedItem
            .Remove()
        End With
        MessageBox.Show("Are you sure delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, New EventHandler(AddressOf DeleteData))
    End Sub

Private Sub DeleteData(ByVal sender As Object, ByVal e As EventArgs)
        Dim conn As New Connection(Connectiondb)
        If Me.updateinputalltrans = False Then
            If Me.listviewpos.Items.Count > 0 Then
                For Each del As ListViewItem In listviewpos.Items
                    conn.delete_dtpospart(del.Text)
                Next
            End If
        End If
    End Sub

delete_dtpospart使用存储过程声明与数据库的连接

1 个答案:

答案 0 :(得分:0)

使用此代码可以帮助您解决问题

Dim Button = MessageBox.Show _
        ("Are you sure you want to delete this Data?", _
        "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
          If Button = Windows.Forms.DialogResult.Yes Then
        DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
        da.Update(ds, "walkindata")
        If Not ListView1.SelectedItems.Count = 0 Then
        ListView1.Items.Remove(ListView1.SelectedItems.Item(0))
           MsgBox("customer removed in the list.", MsgBoxStyle.Critical)
        Else
        MsgBox("No Customer Selected.", MsgBoxStyle.Critical)
        End If
        Else
        MsgBox("delete is cancel", MsgBoxStyle.Information)
        End If