Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Public Class insertToDB
Dim conDB As New connectDB
Dim conn As New SqlConnection(conDB.connection)
Public Sub insertTeacher(ByVal Teacher_ID As String, ByVal Teacher_Name As String, ByVal Teacher_Room As String, ByVal Teacher_Email As String, ByVal Teacher_Telephone As String)
Dim sql As String = "insert into Teacher values(?,?,?,?,?)"
Dim cmd As New SqlCommand(sql, conn)
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
With cmd
.Parameters.Add("?", SqlDbType.NChar, 8, "Teacher_ID").Value = Teacher_ID
.Parameters.Add("?", SqlDbType.VarChar, 30, "Teacher_Name").Value = Teacher_Name
.Parameters.Add("?", SqlDbType.NChar, 6, "Teacher_Room").Value = Teacher_Room
.Parameters.Add("?", SqlDbType.VarChar, 30, "Teacher_Email").Value = Teacher_Email
.Parameters.Add("?", SqlDbType.NChar, 10, "Teacher_Telephone").Value = Teacher_Telephone
.ExecuteNonQuery()
End With
End Sub
Function runIDinsert(ByVal tableName As String, ByVal column As String) As Integer
Dim sql As String = "select" & column & "from" & tableName & "order by" & column
Dim da As New SqlDataAdapter(sql, conn)
Dim ds As New DataSet
da.Fill(ds, "Teacher_ID")
Dim id As Integer
If ds.Tables("Teacher_ID").Rows.Count <> 0 Then
id = ds.Tables("Teacher_ID").Rows(0).Item(column) + 1
Else
id = 1
End If
Return id
End Function
Public Sub insertStudent(ByVal Student_ID As String, ByVal Student_Name As String, ByVal Student_GPA As Integer, ByVal Student_Address As String, ByVal Student_Gender As Char, ByVal Student_Bestfriend As String, ByVal Student_Telephone As String, ByVal Student_Email As String)
Dim sql As String = "insert into Student values(?,?,?,?,?,?,?,?)"
Dim cmd As New SqlCommand(sql, conn)
With conn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
With cmd
.Parameters.Add("?", SqlDbType.NChar, 11, "Student_ID").Value = Student_ID
.Parameters.Add("?", SqlDbType.VarChar, 30, "Student_Name").Value = Student_Name
.Parameters.Add("?", SqlDbType.Float, 4, "Student_GPA").Value = Student_GPA
.Parameters.Add("?", SqlDbType.VarChar, 70, "Student_Address").Value = Student_Address
.Parameters.Add("?", SqlDbType.Char, 1, "Student_Gender").Value = Student_Gender
.Parameters.Add("?", SqlDbType.VarChar, 30, "Student_Bestfriend").Value = Student_Bestfriend
.Parameters.Add("?", SqlDbType.NChar, 10, "Student_Telephone").Value = Student_Telephone
.Parameters.Add("?", SqlDbType.VarChar, 30, "Student_Email").Value = Student_Email
.ExecuteNonQuery()
End With
End Sub
End Class