01.
int
intNumRows;
02.
strSQL =
"SELECT COUNT(*) FROM customer WHERE CustomerID = '"
+
this
.txtCustomerID.Text +
"' "
;
03.
objCmd =
new
SqlCommand(strSQL, objConn);
04.
intNumRows = Convert.ToInt32(objCmd.ExecuteScalar());
05.
06.
if
(intNumRows > 0)
07.
{
08.
this
.pnlAdd.Visible =
false
;
09.
this
.lblStatus.Visible =
true
;
10.
this
.lblStatus.Text =
"CustomerID already exists."
;
11.
}
12.
else
13.
{
14.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
+
15.
" VALUES "
+
16.
" ('"
+
this
.txtCustomerID.Text +
"','"
+
this
.txtName.Text +
"','"
+
this
.txtEmail.Text +
"', "
+
17.
" '"
+
this
.txtCountryCode.Text +
"','"
+
this
.txtBudget.Text +
"','"
+
this
.txtUsed.Text +
"')"
;
18.
19.
objCmd =
new
SqlCommand();
20.
objCmd.Connection = objConn;
21.
objCmd.CommandText = strSQL;
22.
objCmd.CommandType = CommandType.Text;
23.
24.
this
.pnlAdd.Visible =
false
;
25.
26.
try
27.
{
28.
objCmd.ExecuteNonQuery();
29.
this
.lblStatus.Text =
"Record Inserted"
;
30.
this
.lblStatus.Visible =
true
;
31.
}
32.
catch
(Exception ex)
33.
{
34.
this
.lblStatus.Visible =
true
;
35.
this
.lblStatus.Text =
"Record can not insert Error ("
+ ex.Message +
")"
;
36.
}