Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
If IsDataComplete() = False Then
Exit Sub
End If
sql = "INSERT INTO Jewelry "
If Not (PictureBox1.Image Is Nothing) Then
sql &= "(Jew_ID,TypeJew_ID,Picture)" &
"VALUES(@jew,@Type,@pic)"
Else
sql &= "(Jew_ID,TypeJew_ID)" &
"VALUES(@jew,@Type)"
End If
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("@jew", txtjewid.Text)
command.Parameters.AddWithValue("@Type", txttypeid.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