|
-
Aug 5th, 2006, 01:01 AM
#1
Thread Starter
Member
[2005] How to delete button from database-using listview
how to delete the records from the database? this are my codes: can help me?? urgent reply!!!!
Public Class DeleteFormf
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()
'While dr.Read Then
'TextBox2.Text = dr("ItemId")
'TextBox1.Text = dr("ReferenceNo")
'cbxtype.Text = dr("ItemCategory")
'DateTimePicker1.Text = dr("DateDeleted")
'End While
'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
Private Sub DeleteFormf_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.item' table. You can move, or remove it, as needed.
' Me.ItemTableAdapter.Fill(Me.Db1DataSet.item)
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 = "Select * from item where DateDeleted= '" & Format(DateTimePicker1.Text) & "'"
'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 eException As Exception
MessageBox.Show(eException.Message)
End Try
' If cbxtype.Text = "Overdue" Then
lvfine.View = View.Details 'view stuff in listview
lvfine.Columns.Add("ISBN", 60, HorizontalAlignment.Left)
lvfine.Columns.Add("Title", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("Category", 100, HorizontalAlignment.Left)
lvfine.Columns.Add("Classification", 70, HorizontalAlignment.Left)
lvfine.Columns.Add("Status", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("Author", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("DatePublished", 70, HorizontalAlignment.Left)
lvfine.Columns.Add("DateCreated", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("Cost", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("PublisherName", 70, HorizontalAlignment.Left)
lvfine.Columns.Add("ReferenceNo", 80, HorizontalAlignment.Left)
lvfine.Columns.Add("Edition", 80, HorizontalAlignment.Left)
End Sub
Private Sub cbxtype_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxtype.SelectedIndexChanged
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 = "Select * from item where ItemCategory = '" & cbxtype.Text & "'"
'create a new connection
con = New OleDb.OleDbConnection(strcon)
con.Open()
cmd.Connection = con
cmd.CommandText = strselect
dr = cmd.ExecuteReader
lvfine.Items.Clear()
While dr.Read()
Dim Item As New ListViewItem
Item.Text = (dr("ItemId"))
'Item.SubItems.Add(dr(""))
Item.SubItems.Add(dr("ItemTitle"))
Item.SubItems.Add(dr("ItemCategory"))
Item.SubItems.Add(dr("ItemClassification"))
Item.SubItems.Add(dr("Status"))
Item.SubItems.Add(dr("AuthorName"))
Item.SubItems.Add(dr("DateOfPublished"))
Item.SubItems.Add(dr("DateCreated"))
Item.SubItems.Add(dr("CostPriceOfItem"))
Item.SubItems.Add(dr("PublisherName"))
Item.SubItems.Add(dr("ReferenceNo"))
Item.SubItems.Add(dr("Edition"))
lvfine.Items.Add(Item)
End While
dr.Close()
' If cbxtype.Text = "Lost" Then
'lost.ShowDialog()
' End If
Catch eException As Exception
MessageBox.Show(eException.Message)
End Try
' If Not lvfine.SelectedItems.Count = 0 Then tbxdays.Text = lvfine.SelectedItems(0).SubItems(3).Text
End Sub
Private Sub lvfine_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvfine.SelectedIndexChanged
End Sub
End Class
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
|