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