01.
Private
Sub
btn_Add_Staff_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btn_Add_Staff.Click
02.
If
txtProID.Text.Trim =
""
Or
txtProName.Text.Trim =
""
Or
txtProPrice.Text.Trim =
""
Then
03.
MessageBox.Show(
"กรอกข้อมูลให้ครบทุกรายการ"
,
"Warning"
, MessageBoxButtons.OK, MessageBoxIcon.Warning)
04.
Exit
Sub
05.
End
If
06.
07.
08.
sb =
New
StringBuilder()
09.
sb.Append(
"INSERT INTO Product(ProID, ProName, ProPrice)"
)
10.
sb.Append(
" VALUES (@ProID, @ProName, @ProPrice)"
)
11.
12.
Dim
sqlAdd
As
String
13.
sqlAdd = sb.ToString()
14.
15.
exeCommand =
New
SqlCommand()
16.
17.
18.
Try
19.
With
exeCommand
20.
.CommandText = sqlAdd
21.
.Connection = conn
22.
23.
.Parameters.Add(
"@ProID"
, SqlDbType.NVarChar).Value = txtProID.Text.Trim()
24.
.Parameters.Add(
"@ProName"
, SqlDbType.NVarChar).Value = txtProName.Text.Trim()
25.
.Parameters.Add(
"@ProPrice"
, SqlDbType.Float).Value = txtProPrice.Text.Trim()
26.
.ExecuteNonQuery()
27.
End
With
28.
29.
MessageBox.Show(
"เพิ่มข้อมูลลูกค้าลงฐานข้อมูลแล้ว"
,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
30.
31.
Catch
32.
MessageBox.Show(
"เกิดความผิดพลาดจากการกรอกข้อมูล รหัสลูกค้าอาจซ้ำ กรุณาตรวจสอบ"
,
"Error"
, MessageBoxButtons.OK, MessageBoxIcon.
Error
)
33.
Exit
Sub
34.
End
Try
35.
36.
ClearData()
37.
ShowData()
38.
FormatDataGrid()
39.
End
Sub