/
frmRemoveCustomer.vb
68 lines (51 loc) · 2.28 KB
/
frmRemoveCustomer.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Imports System.Data
Imports System.Data.OleDb
Public Class frmRemoveCustomer
Public accConnection As New OleDbConnection
Private Sub frmRemoveCustomers_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If frmLoginForm.accConnection.State <> ConnectionState.Open Then
frmLoginForm.accConnection.Open()
End If
accConnection = frmLoginForm.accConnection
Dim strSQL As String = "SELECT cust_name FROM Customer"
Dim da As New OleDbDataAdapter(strSQL, accConnection)
Dim ds As New DataSet
da.Fill(ds, "Customer")
Dim dt As DataTable = ds.Tables(0)
Dim dr As DataRow
For Each dr In dt.Rows()
txtcbCustomerRemove.Items.Add(dr("cust_name"))
Next
txtcbCustomerRemove.SelectedIndex = -1
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnRemove.Click
Dim cmdString As String = "DELETE * FROM Customer WHERE cust_name = '" & _
Me.txtcbCustomerRemove.SelectedItem & "'"
Dim da As New OleDbDataAdapter(cmdString, accConnection)
Dim ds As New DataSet
Dim accCommand As New OleDbCommand
accCommand.Connection = frmLoginForm.accConnection
accCommand.CommandType = CommandType.Text
accCommand.CommandText = cmdString
Call RemoveParameters(accCommand)
Dim intRemove As Integer
intRemove = accCommand.ExecuteNonQuery()
If intRemove = 0 Then
MsgBox("Sorry, data deletion failed.")
'Else, assume it went through OK.
Else
btnRemove.Enabled = False
End If
End Sub
Private Sub RemoveParameters(ByRef acccmd As OleDbCommand)
acccmd.Parameters.Add("@cust_name", OleDbType.Char).Value = _
Me.txtcbCustomerRemove.SelectedItem
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
frmRemove.Show()
End Sub
End Class