Private Sub ButtonSave_Click() Handles ButtonSave.Click
If IsDataComplete() = False Then
Exit Sub
End If
sql = "INSERT INTO Employee "
If Not (PictureBox1.Image Is Nothing) Then
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add,Picture)" &
"VALUES(@id,@name,@last,@age,@num,@add,@pic)"
Else
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add)" &
"VALUES(@id,@name,@last,@age,@num,@add)"
End If
Dim command As New SqlCommand(sql, conection)
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("Emp_ID", TextID.Text)
command.Parameters.AddWithValue("Emp_Name", Textname.Text)
command.Parameters.AddWithValue("Emp_Las", Textlats.Text)
command.Parameters.AddWithValue("Emp_Age", Textage.Text)
command.Parameters.AddWithValue("Emp_Num", Textnum.Text)
command.Parameters.AddWithValue("Emp_Add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim pic() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", pic)
End If
Dim result As Integer = command.ExecuteNonQuery()
If result = -1 Then
MessageBox.Show("เกิดข้อผิดพลาดไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
ButtonAdd.PerformClick()
End If
End Sub
Private Sub ButtonSave_Click() Handles ButtonSave.Click
If IsDataComplete() = False Then
Exit Sub
End If
sql = "INSERT INTO Employee "
If Not (PictureBox1.Image Is Nothing) Then
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add,Picture)" &
"VALUES(@id,@name,@last,@age,@num,@add,@pic)"
Else
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add)" &
"VALUES(@id,@name,@last,@age,@num,@add)"
End If
Dim command As New SqlCommand(sql, conection)
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("Emp_ID", TextID.Text)
command.Parameters.AddWithValue("Emp_Name", Textname.Text)
command.Parameters.AddWithValue("Emp_Las", Textlats.Text)
command.Parameters.AddWithValue("Emp_Age", Textage.Text)
command.Parameters.AddWithValue("Emp_Num", Textnum.Text)
command.Parameters.AddWithValue("Emp_Add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim pic() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", pic)
End If
Dim result As Integer = command.ExecuteNonQuery()
If result = -1 Then
MessageBox.Show("เกิดข้อผิดพลาดไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
ButtonAdd.PerformClick()
End If
End Sub