01.
Private
Sub
ButtonSave_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
ButtonSave.Click
02.
03.
If
Not
(IsNumeric(TextNumFloors.Text)
OrElse
Is
Integer
(TextNumFloors.Text))
Then
04.
05.
MessageBox.Show(
"จำนวนชั้นต้องเป็นเลขจำนวนเต็ม"
)
06.
Exit
Sub
07.
08.
ElseIf
Not
(IsNumeric(TextRoomsPerFloor.Text)
OrElse
IsInteger(TextRoomsPerFloor.Text))
Then
09.
10.
MessageBox.Show(
"จำนวนห้องในแต่ละชั้นต้องเป็นเลขจำนวนเต็ม"
)
11.
Exit
Sub
12.
13.
ElseIf
Not
IsNumeric(TextNumFloors.Text)
Then
14.
15.
MessageBox.Show(
"ค่าเช่าต้องเป็นตัวเลข"
)
16.
Exit
Sub
17.
End
If
18.
19.
If
hasRows
Then
20.
sql =
"UPDATA Ref SET "
&
"NumFloors = @floors, "
&
"RoomsPerFloor = @rooms, "
&
"Rental = @rent"
21.
22.
Else
23.
sql =
"INSERT INTO Ref(NumFloors,RoomsPerFloors,Rental) "
&
"VALUES(@floors, @rooms, @rent)"
24.
End
If
25.
26.
command =
New
SqlCommand(sql, connection)
27.
command.Parameters.Clear()
28.
command.Parameters.AddWithValue(
"floors"
, TextNumFloors.Text)
29.
command.Parameters.AddWithValue(
"rooms"
, TextRoomsPerFloor.Text)
30.
command.Parameters.AddWithValue(
"rent"
, TextRental.Text)
31.
32.
Dim
r
As
Integer
= command.ExecuteNonQuery()
33.
34.
If
r = 1
Then
35.
MessageBox.Show(
"ปรับปรุงข้อมูล"
)
36.
connection.Close()
37.
FormRef_load(sender, e)
38.
Else
39.
MessageBox.Show(
"เกิดข้อผิดพลาด"
)
40.
End
If
41.
End
Sub