001.
<%@ Page Language=
"C#"
Debug=
"true"
%>
002.
<%@ import
Namespace
=
"System.Data"
%>
003.
<%@ import
Namespace
=
"System.Data.OleDb"
%>
004.
<script runat=
"server"
>
005.
OleDbConnection objConn = new OleDbConnection();
006.
OleDbCommand objCmd = new OleDbCommand();
007.
OleDbDataReader dtReader;
008.
String
strConnString,strSQL;
009.
010.
void Page_Load(object sender,EventArgs e)
011.
{
012.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+
013.
Server.MapPath(
"database/mydatabase.mdb"
) +
";Jet OLEDB:Database Password=;"
;
014.
objConn = new OleDbConnection(strConnString);
015.
objConn.Open();
016.
017.
if(!Page.IsPostBack)
018.
{
019.
ViewData();
020.
}
021.
}
022.
023.
void ViewData()
024.
{
025.
//*** DataTable ***//
026.
OleDbDataAdapter dtAdapter;
027.
DataTable dt = new DataTable();
028.
strSQL =
"SELECT * FROM customer WHERE CustomerID = '"
+ Request.QueryString[
"CustomerID"
] +
"' "
;
029.
dtAdapter = new OleDbDataAdapter(strSQL, objConn);
030.
dtAdapter.Fill(dt);
031.
032.
if(dt.Rows.Count > 0)
033.
{
034.
this.txtCustomerID.Text = (string)dt.Rows[0][
"CustomerID"
];
035.
this.txtName.Text = (string)dt.Rows[0][
"Name"
];
036.
this.txtEmail.Text = (string)dt.Rows[0][
"Email"
];
037.
this.txtCountryCode.Text = (string)dt.Rows[0][
"CountryCode"
];
038.
this.txtBudget.Text = (string)dt.Rows[0][
"Budget"
].ToString();
039.
this.txtUsed.Text = (string)dt.Rows[0][
"Used"
].ToString();
040.
}
041.
}
042.
043.
void btnSave_Click(
Object
sender, EventArgs e)
044.
{
045.
strSQL =
"UPDATE customer SET "
+
046.
" CustomerID = '"
+ this.txtCustomerID.Text +
"' "
+
047.
" ,Name = '"
+ this.txtName.Text +
"' "
+
048.
" ,Email = '"
+ this.txtEmail.Text +
"' "
+
049.
" ,CountryCode = '"
+ this.txtCountryCode.Text +
"' "
+
050.
" ,Budget = '"
+ this.txtBudget.Text +
"' "
+
051.
" ,Used = '"
+ this.txtUsed.Text +
"' "
+
052.
" WHERE CustomerID = '"
+ Request.QueryString[
"CustomerID"
] +
"' "
;
053.
054.
objCmd = new OleDbCommand();
055.
objCmd.Connection = objConn;
056.
objCmd.CommandText = strSQL;
057.
objCmd .CommandType = CommandType.Text;
058.
059.
060.
this.pnlAdd.Visible = false;
061.
062.
try
063.
{
064.
objCmd.ExecuteNonQuery();
065.
this.lblStatus.Text =
"Record Updated"
;
066.
this.lblStatus.Visible = true;
067.
}
068.
catch (Exception ex)
069.
{
070.
this.lblStatus.Text =
"Record can not update"
;
071.
}
072.
073.
}
074.
075.
void Page_UnLoad()
076.
{
077.
objConn.Close();
078.
objConn = null;
079.
}
080.
081.
</script>
082.
<html>
083.
<head>
084.
<title>ThaiCreate.Com ASP.NET - Microsoft Access</title>
085.
</head>
086.
<body>
087.
<form id=
"form1"
runat=
"server"
>
088.
<asp:Panel id=
"pnlAdd"
runat=
"server"
>
089.
<table width=
"353"
border=
"1"
>
090.
<tbody>
091.
<tr>
092.
<td width=
"102"
>
093.
<asp:Label id=
"lblCustomerID"
runat=
"server"
text=
"CustomerID"
></asp:Label></td>
094.
<td width=
"235"
>
095.
<asp:TextBox id=
"txtCustomerID"
runat=
"server"
Width=
"79px"
></asp:TextBox>
096.
</td>
097.
</tr>
098.
<tr>
099.
<td>
100.
<asp:Label id=
"lblName"
runat=
"server"
text=
"Name"
></asp:Label></td>
101.
<td>
102.
<asp:TextBox id=
"txtName"
runat=
"server"
Width=
"177px"
></asp:TextBox>
103.
</td>
104.
</tr>
105.
<tr>
106.
<td>
107.
<asp:Label id=
"lblEmail"
runat=
"server"
text=
"Email"
></asp:Label></td>
108.
<td>
109.
<asp:TextBox id=
"txtEmail"
runat=
"server"
Width=
"155px"
></asp:TextBox>
110.
</td>
111.
</tr>
112.
<tr>
113.
<td>
114.
<asp:Label id=
"lblCountryCode"
runat=
"server"
text=
"CountryCode"
></asp:Label></td>
115.
<td>
116.
<asp:TextBox id=
"txtCountryCode"
runat=
"server"
Width=
"38px"
></asp:TextBox>
117.
</td>
118.
</tr>
119.
<tr>
120.
<td>
121.
<asp:Label id=
"lblBudget"
runat=
"server"
text=
"Budget"
></asp:Label></td>
122.
<td>
123.
<asp:TextBox id=
"txtBudget"
runat=
"server"
Width=
"76px"
></asp:TextBox>
124.
</td>
125.
</tr>
126.
<tr>
127.
<td>
128.
<asp:Label id=
"lblUsed"
runat=
"server"
text=
"Used"
></asp:Label></td>
129.
<td>
130.
<asp:TextBox id=
"txtUsed"
runat=
"server"
Width=
"76px"
></asp:TextBox>
131.
</td>
132.
</tr>
133.
</tbody>
134.
</table>
135.
<br />
136.
<asp:Button id=
"btnSave"
onclick=
"btnSave_Click"
runat=
"server"
Text=
"Save"
></asp:Button>
137.
<br />
138.
</asp:Panel>
139.
<asp:Label id=
"lblStatus"
runat=
"server"
visible=
"True"
></asp:Label>
140.
</form>
141.
</body>
142.
</html>