01.
Sub
btnSave_Click(sender
As
Object
, e
As
EventArgs)
02.
Dim
intNumRows
As
Integer
03.
strSQL =
"SELECT COUNT(*) FROM customer WHERE CustomerID = '"
&
Me
.txtCustomerID.Text &
"' "
04.
objCmd =
New
SqlCommand(strSQL, objConn)
05.
intNumRows = objCmd.ExecuteScalar()
06.
07.
IF intNumRows > 0
Then
08.
Me
.pnlAdd.Visible =
False
09.
Me
.lblStatus.Visible =
True
10.
Me
.lblStatus.Text =
"CustomerID already exist."
11.
Else
12.
13.
14.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
& _
15.
" VALUES "
& _
16.
" ('"
&
Me
.txtCustomerID.Text &
"','"
&
Me
.txtName.Text &
"','"
&
Me
.txtEmail.Text &
"', "
& _
17.
" '"
&
Me
.txtCountryCode.Text &
"','"
&
Me
.txtBudget.Text &
"','"
&
Me
.txtUsed.Text &
"')"
18.
19.
objCmd =
New
SqlCommand
20.
With
objCmd
21.
.Connection = objConn
22.
.CommandText = strSQL
23.
.CommandType = CommandType.Text
24.
End
With
25.
26.
Me
.pnlAdd.Visible =
False
27.
Try
28.
objCmd.ExecuteNonQuery()
29.
Me
.lblStatus.Text =
"Record Inserted"
30.
Me
.lblStatus.Visible =
True
31.
Catch
ex
As
Exception
32.
Me
.lblStatus.Visible =
True
33.
Me
.lblStatus.Text =
"Record can not insert Error ("
& ex.Message &
")"
34.
End
Try
35.
36.
End
IF
37.
38.
End
Sub