Private Sub btn_addnew_Click(sender As Object, e As EventArgs) Handles btn_addnew.Click
If txt_add_numroom.Text = "" Or txt_add_price.Text = "" Or txt_add_name.Text = "" Or txt_add_tell.Text = "" Or txt_add_address.Text = "" Or txt_add_code.Text = "" Then
msg_error("กรอกข้อมูลให้ครบ")
Return
End If
If Not IsNumeric(txt_add_price.Text) Then
msg_error("กรอกราคาเป็นตัวเลขเท่านั้น")
Return
End If
If pic_add.Image Is Nothing Then
Getroom = "insert into renter(renter_numroom,renter_name,renter_tell,renter_address,renter_code,renter_price) values(@numroom,@name,@tell,@address,@code,@price)"
Else
Getroom = "insert into renter(renter_numroom,renter_name,renter_tell,renter_address,renter_code,renter_price,renter_image) values(@numroom,@name,@tell,@address,@code,@price,@img)"
End If
cmd = New OleDb.OleDbCommand(Getroom, cn)
'OleDbCommand objCmd = new OleDbCommand();
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("numroom", txt_add_numroom.Text)
cmd.Parameters.AddWithValue("name", txt_add_name.Text)
cmd.Parameters.AddWithValue("tell", txt_add_tell.Text)
cmd.Parameters.AddWithValue("address", txt_add_address.Text)
cmd.Parameters.AddWithValue("code", txt_add_code.Text)
cmd.Parameters.AddWithValue("price", txt_add_price.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 cmd.ExecuteNonQuery = 0 Then ***ชี้ error ตรงนี้***
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
End If
End Sub
Private Sub btn_select_picture_Click(sender As Object, e As EventArgs) Handles btn_select_picture.Click
If openfile_renter.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim img As Image
img = Image.FromFile(openfile_renter.FileName)
pic_add.Image = img
End If
End Sub
End Class