Public Class Frm_manag_coffice
Private Sub btn_addnew_Click(sender As Object, e As EventArgs) Handles btn_addnew.Click
If txt_add_id.Text = "" Or txt_add_name.Text = "" Or txt_add_hot.Text = "" Or txt_add_cool.Text = "" Or txt_add_spin.Text = "" Then
msg_error("กรุณากรอกข้อมูลให้ครบ")
Return
End If
If Not IsNumeric(txt_add_hot.Text) Or Not IsNumeric(txt_add_cool.Text) Or Not IsNumeric(txt_add_spin) Then
End If
If pic_add.Image Is Nothing Then
SQL = "insert into coffee(coffee_ID, coffee_name, coffee_hot, coffee_cool, coffee_spin) values (@id,@name,@hot,@cool,@spin)"
Else
SQL = "insert into coffee(coffee_ID, coffee_name, coffee_hot, coffee_cool, coffee_spin, coffee_image) values (@id, @name, @hot, @cool, @spin, @img)"
End If
cmd = New SqlClient.SqlCommand(SQL, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("id", txt_add_id.Text)
cmd.Parameters.AddWithValue("name", txt_add_name.Text)
cmd.Parameters.AddWithValue("hot", txt_add_hot.Text)
cmd.Parameters.AddWithValue("cool", txt_add_cool.Text)
cmd.Parameters.AddWithValue("spin", txt_add_spin.Text)
If Not pic_add.Image Is Nothing Then
''เพิ่มรูปภาพลงฐานข้อมูล
Dim mem As New IO.MemoryStream
pic_add.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
cmd.Parameters.AddWithValue("img", pic_for_add)
End If
If Not cmd.ExecuteNonQuery = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
End If