Imports System.Data.SqlClient
Public Class frmAddSubject
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim strsql As String
Dim userid As String
Private Sub btnOKSubject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOKSubject.Click
If (txtIDSubject.Text = "" Or txtNameSubject.Text = "") Then
MessageBox.Show("กุรณากรอกข้อมูลรายวิชาให้ครบถ้วน")
ElseIf (txtIDSubject.Text.Length < 8) Then
MessageBox.Show("กุรณากรอกรหัสรายวิชาให้ครบถ้วน")
Else
Try
strsql = "INSERT INTO Subject(sub_id,sub_name)"
strsql &= "VALUES('" & txtIDSubject.Text & "','" & txtNameSubject.Text & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
MessageBox.Show("เพิ่มรายวิชาเรียนร้อยแล้ว")
End With
txtIDSubject.Clear()
txtNameSubject.Clear()
Catch ex As Exception
End Try
strsql = "INSERT INTO Teaching(teac_id,sub_id)"
strsql &= "VALUES('" & userid & "','" & txtIDSubject.Text & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
MessageBox.Show("เพิ่มรายวิชาเรียนร้อยแล้ว")
End With
txtIDSubject.Clear()
txtNameSubject.Clear()
End If
End Sub
Private Sub frmAddSubject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
userid = frmMain.user_idLogin
Label5.Text = userid
con.ConnectionString = "Data Source=localhost; Initial Catalog=SeniorProjectOCR; Integrated Security= true"
cmd.Connection = con
con.Open()
End Sub
End Class