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