-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUBJECT.VB
70 lines (50 loc) · 2.05 KB
/
SUBJECT.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
69
70
Imports System.Data.SqlClient
Public Class SUBJECT
Private Sub SUBJECT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New SqlConnection(My.Settings.LIBRARY)
Dim cmd As New SqlCommand("SELECT * FROM SUBJECT", con)
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
ComboBox1.DataSource = table
ComboBox1.DisplayMember = "SUBJECT"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
Dim con As New SqlConnection(My.Settings.LIBRARY)
Dim cmd As New SqlCommand("SELECT * FROM SUBJECT", con)
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
ComboBox1.DataSource = table
ComboBox1.DisplayMember = "SUBJECT"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim con As New SqlConnection(My.Settings.LIBRARY)
Dim cmd As New SqlCommand("INSERT INTO SUBJECT (SUBJECT) VALUES (@SUBJECT)", con)
cmd.Parameters.Add("@SUBJECT", SqlDbType.VarChar).Value = TextBox1.Text
Dim adapter As New SqlDataAdapter(cmd)
Dim tbl As New DataTable()
adapter.Fill(tbl)
If tbl.Rows.Count() <= 0 Then
MsgBox("DONE")
Button1.PerformClick()
TextBox1.Clear()
Else
'DO NOTHING
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim con As New SqlConnection(My.Settings.LIBRARY)
Dim cmd As New SqlCommand("DELETE FROM SUBJECT WHERE SUBJECT='" + ComboBox1.Text + "'", con)
con.Open()
cmd.ExecuteNonQuery()
MsgBox("DONE")
Button1.PerformClick()
con.Dispose()
End Sub
End Class