001.
<%@ Import Namespace=
"System.Data"
%>
002.
<%@ Import Namespace=
"System.Data.OracleClient"
%>
003.
<%@ Page Language=
"C#"
Debug=
"true"
%>
004.
<script runat=
"server"
>
005.
006.
void
Page_Load(
object
sender,EventArgs e)
007.
{
008.
009.
}
010.
011.
void
btnSave_Click(Object sender, EventArgs e)
012.
{
013.
OracleConnection objConn =
new
OracleConnection();
014.
OracleCommand objCmd =
new
OracleCommand();
015.
String strConnString,strSQL;
016.
OracleTransaction Trans;
017.
018.
this
.pnlAdd.Visible =
false
;
019.
020.
strConnString =
"Data Source=TCDB;User Id=myuser;Password=mypassword;"
;
021.
objConn.ConnectionString = strConnString;
022.
objConn.Open();
023.
024.
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted);
025.
026.
objCmd.Connection = objConn;
027.
objCmd.Transaction = Trans;
028.
029.
try
030.
{
031.
032.
033.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
+
034.
" VALUES "
+
035.
" ('"
+
this
.txtCustomerID.Text +
"','"
+
this
.txtName.Text +
"','"
+
this
.txtEmail.Text +
"', "
+
036.
" '"
+
this
.txtCountryCode.Text +
"','"
+
this
.txtBudget.Text +
"','"
+
this
.txtUsed.Text +
"')"
;
037.
038.
objCmd.CommandText = strSQL;
039.
objCmd.CommandType = CommandType.Text;
040.
objCmd.ExecuteNonQuery();
041.
042.
043.
044.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
+
045.
" VALUES "
+
046.
" ('"
+
this
.txtCustomerID.Text +
"','"
+
this
.txtName.Text +
"','"
+
this
.txtEmail.Text +
"', "
+
047.
" '"
+
this
.txtCountryCode.Text +
"','"
+
this
.txtBudget.Text +
"','"
+
this
.txtUsed.Text +
"')"
;
048.
049.
objCmd.CommandText = strSQL;
050.
objCmd.CommandType = CommandType.Text;
051.
objCmd.ExecuteNonQuery();
052.
053.
054.
Trans.Commit();
055.
056.
this
.lblStatus.Text =
"Record Inserted"
;
057.
this
.lblStatus.Visible =
true
;
058.
059.
}
060.
catch
(Exception ex)
061.
{
062.
Trans.Rollback();
063.
064.
this
.lblStatus.Visible =
true
;
065.
this
.lblStatus.Text =
"Record can not insert Error ("
+ ex.Message +
")"
;
066.
}
067.
068.
069.
objConn.Close();
070.
objConn =
null
;
071.
072.
}
073.
074.
</script>
075.
<html>
076.
<head>
077.
<title>ThaiCreate.Com ASP.NET - Oracle</title>
078.
</head>
079.
<body>
080.
<form id=
"form1"
runat=
"server"
>
081.
<asp:Panel id=
"pnlAdd"
runat=
"server"
>
082.
<table width=
"353"
border=
"1"
>
083.
<tbody>
084.
<tr>
085.
<td width=
"102"
>
086.
<asp:Label id=
"lblCustomerID"
runat=
"server"
text=
"CustomerID"
></asp:Label></td>
087.
<td width=
"235"
>
088.
<asp:TextBox id=
"txtCustomerID"
runat=
"server"
Width=
"79px"
></asp:TextBox>
089.
</td>
090.
</tr>
091.
<tr>
092.
<td>
093.
<asp:Label id=
"lblName"
runat=
"server"
text=
"Name"
></asp:Label></td>
094.
<td>
095.
<asp:TextBox id=
"txtName"
runat=
"server"
Width=
"177px"
></asp:TextBox>
096.
</td>
097.
</tr>
098.
<tr>
099.
<td>
100.
<asp:Label id=
"lblEmail"
runat=
"server"
text=
"Email"
></asp:Label></td>
101.
<td>
102.
<asp:TextBox id=
"txtEmail"
runat=
"server"
Width=
"155px"
></asp:TextBox>
103.
</td>
104.
</tr>
105.
<tr>
106.
<td>
107.
<asp:Label id=
"lblCountryCode"
runat=
"server"
text=
"CountryCode"
></asp:Label></td>
108.
<td>
109.
<asp:TextBox id=
"txtCountryCode"
runat=
"server"
Width=
"38px"
></asp:TextBox>
110.
</td>
111.
</tr>
112.
<tr>
113.
<td>
114.
<asp:Label id=
"lblBudget"
runat=
"server"
text=
"Budget"
></asp:Label></td>
115.
<td>
116.
<asp:TextBox id=
"txtBudget"
runat=
"server"
Width=
"76px"
></asp:TextBox>
117.
</td>
118.
</tr>
119.
<tr>
120.
<td>
121.
<asp:Label id=
"lblUsed"
runat=
"server"
text=
"Used"
></asp:Label></td>
122.
<td>
123.
<asp:TextBox id=
"txtUsed"
runat=
"server"
Width=
"76px"
></asp:TextBox>
124.
</td>
125.
</tr>
126.
</tbody>
127.
</table>
128.
<br />
129.
<asp:Button id=
"btnSave"
onclick=
"btnSave_Click"
runat=
"server"
Text=
"Save"
></asp:Button>
130.
<br />
131.
</asp:Panel>
132.
<asp:Label id=
"lblStatus"
runat=
"server"
visible=
"False"
></asp:Label>
133.
</form>
134.
</body>
135.
</html>