01.
Imports
System.Data.SqlClient
02.
Public
Class
frmAddSubject
03.
Dim
con
As
New
SqlConnection
04.
Dim
cmd
As
New
SqlCommand
05.
Dim
strsql
As
String
06.
Dim
userid
As
String
07.
Private
Sub
btnOKSubject_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnOKSubject.Click
08.
09.
10.
If
(txtIDSubject.Text =
""
Or
txtNameSubject.Text =
""
)
Then
11.
MessageBox.Show(
"กุรณากรอกข้อมูลรายวิชาให้ครบถ้วน"
)
12.
13.
ElseIf
(txtIDSubject.Text.Length < 8)
Then
14.
MessageBox.Show(
"กุรณากรอกรหัสรายวิชาให้ครบถ้วน"
)
15.
16.
Else
17.
Try
18.
strsql =
"INSERT INTO Subject(sub_id,sub_name)"
19.
strsql &=
"VALUES('"
& txtIDSubject.Text &
"','"
& txtNameSubject.Text &
"')"
20.
21.
With
cmd
22.
.Connection = con
23.
.CommandText = strsql
24.
25.
.CommandType = CommandType.Text
26.
.ExecuteNonQuery()
27.
MessageBox.Show(
"เพิ่มรายวิชาเรียนร้อยแล้ว"
)
28.
End
With
29.
txtIDSubject.Clear()
30.
txtNameSubject.Clear()
31.
32.
Catch
ex
As
Exception
33.
34.
End
Try
35.
strsql =
"INSERT INTO Teaching(teac_id,sub_id)"
36.
strsql &=
"VALUES('"
& userid &
"','"
& txtIDSubject.Text &
"')"
37.
38.
With
cmd
39.
.Connection = con
40.
.CommandText = strsql
41.
42.
.CommandType = CommandType.Text
43.
.ExecuteNonQuery()
44.
MessageBox.Show(
"เพิ่มรายวิชาเรียนร้อยแล้ว"
)
45.
End
With
46.
txtIDSubject.Clear()
47.
txtNameSubject.Clear()
48.
49.
End
If
50.
51.
End
Sub
52.
53.
Private
Sub
frmAddSubject_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
54.
userid = frmMain.user_idLogin
55.
Label5.Text = userid
56.
57.
con.ConnectionString =
"Data Source=localhost; Initial Catalog=SeniorProjectOCR; Integrated Security= true"
58.
cmd.Connection = con
59.
con.Open()
60.
61.
End
Sub
62.
End
Class