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