H NG D N L P TRÌNH WEB V I ASPƯỚ Ẫ Ậ Ớ
CHO CSDL M U Ẫ COSODULIEUQUANLYHSSV.MDB
1.K T N I C S D LI UẾ Ố Ơ Ở Ữ Ệ
M t p tin k t n i vào c s d li u ở ậ ế ố ơ ở ữ ệ ketnoicosodulieu.asp (s a đo n Code sau cho phù h p v iử ạ ợ ớ
CSDL c a b n…)ủ ạ
Trong bài m u: ẫ
- Th m c ch a CSDL đ c ch đ nh là: ư ụ ứ ượ ỉ ị database
- Tên c s d li u là:ơ ở ữ ệ cosodulieuquanlyhssv.mdb
'THU MUC CHUA CSDL CUA BAN
strDBFolder = Server.MapPath("database")
'TEN CO SO DU LIEU CUA BAN
strDBFileName = "/cosodulieuquanlyhssv.mdb"
2. T O M T TRANG WEB L Y THÔNG TIN TRONG CSDLẠ Ộ Ấ
Ví d :ụ T o trang web xu t thông tin trong b ng danh b ạ ấ ả ạ
l u l i v i tên ư ạ ớ xuat_ds_dienthoai.asp
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!#include file="ketnoicosodulieu.asp">
<p align="center"><b> DANH B ĐI N THO IẠ Ệ Ạ </b></p>
<b><A HREF="them_ds_dienthoai.asp">THÊM S ĐT M IỐ Ớ </A></b>
<%
session.codepage=65001
'TAO SQL LAY THONG TIN TU BANG DANHBA
SQL="SELECT STT, ten, didong, coquan, nharieng, FAX, ghichu FROM danhba;"
set RS = objCn.Execute(sql)
if not rs.eof then
response.write"<table border='2' cellpadding='0' cellspacing='0' style='border-collapse: collapse'
bordercolor='#000080' WIDTH='100%'>"
response.write"<tr height=25 >"
response.write"<td align='center'>STT </td>"
response.write"<td align='center'>H TÊNỌ </td>"
response.write"<td align='center'>DI Đ NGỘ </td>"
response.write"<td align='center'>C QUANƠ </td>"
response.write"<td align='center'>NHÀ RIÊNG </td>"
response.write"<td align='center'>FAX </td>"
response.write"<td align='center'>GHI CHÚ </td>"
'THEM COT CHUC NANG
response.write"<td align='center'>CH C NĂNGỨ </td>" response.write"</tr>"
do while not rs.eof
response.Write"<tr height=25>"
response.Write"<td align='center'> "&rs("STT")&" </td>"
response.Write"<td align='Left'> "&rs("ten")&" </td>"
response.Write"<td align='center'> "&rs("didong")&" </td>"
response.Write"<td align='center'> "&rs("coquan")&" </td>"
response.Write"<td align='center'> "&rs("nharieng")&" </td>"
response.Write"<td align='center'> "&rs("fax")&" </td>"
response.Write"<td align='center'> "&rs("ghichu")&" </td>"
'THEM COT CHUC NANG LIEN KET
response.Write"<td align='center'>"
response.Write"<a href='xoa_ds_dienthoai.asp?xoadienthoai="&rs("STT")&"'>Xoá |</a>"
response.Write"<a href='sua_ds_dienthoai.asp?suadienthoai="&rs("STT")&"'> S a</aử >"
response.Write"</td>"
response.Write"</tr>"
rs.movenext
loop
rs.close
response.write("</table>") 'KET THUC BANG
else
end if
%>
T o liên k t truy n giá tr ạ ế ề ị xoadienthoai
theo mã là STT đ n trang ế
xoa_ds_dienthoai.asp
T o liên k t truy n giá tr ạ ế ề ị suadienthoai theo
mã là STT đ n trang ế sua_ds_dienthoai.asp
3. T O M T TRANG WEB B T KỲ THÊM THÔNG TIN VÀO CSDLẠ Ộ Ấ
Ví d :ụ T o trang web thêm thông tin vào danh b ạ ạ
l u l i v i tên ư ạ ớ them_ds_dienthoai.asp
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!---#include file="ketnoicosodulieu.asp"---->
<p align="center"><b>THÊM S ĐI N TH AI M I VÀO DANH B </b></p>Ố Ệ Ọ Ớ Ạ
<form action="" method=post name=themmoi>
<table border="1" width="100%" id="table1">
<tr><td>S TTố </td><td><input type="text" name="them_STT" size="50"></td></tr>
<tr><td>Tên </td><td><input type="text" name="them_ten" size="50"></td></tr>
<tr><td>ĐT Di Đ ngộ </td><td><input type="text" name="them_didong" size="50"></td></tr>
<tr><td>ĐT C Quanơ </td><td><input type="text" name="them_coquan" size="50"></td></tr>
<tr><td>ĐT Nhà Riêng </td><td><input type="text" name="them_nharieng" size="50"></td></tr>
<tr><td>FAX </td><td><input type="text" name="them_FAX" size="50"></td></tr>
<tr><td>Ghi Chú </td><td><input type="text" name="them_ghichu" size="50"></td></tr>
</table>
<p><input type="submit" value="Submit" name="themmoi_submit">
<input type="reset" value="Reset" name="B2"></p>
</form>
<%
session.codepage=65001
If Request.Form("themmoi_submit")<>"" Then
them_STT =Replace(Request.Form("them_STT"),"'","''")
them_ten =Replace(Request.Form("them_ten"),"'","''")
them_didong =Replace(Request.Form("them_didong"),"'","''")
them_coquan =Replace(Request.Form("them_coquan"),"'","''")
them_nharieng =Replace(Request.Form("them_nharieng"),"'","''")
them_FAX =Replace(Request.Form("them_FAX"),"'","''")
them_ghichu =Replace(Request.Form("them_ghichu"),"'","''")
STRSQL="INSERT INTO danhba(STT,ten,didong,coquan,nharieng,FAX,ghichu) VALUES("
StrSQL=StrSQL &"'" &them_STT&"',"
StrSQL=StrSQL &"'" &them_ten&"',"
StrSQL=StrSQL &"'" &them_didong&"',"
StrSQL=StrSQL &"'" &them_coquan&"',"
StrSQL=StrSQL &"'" &them_nharieng&"',"
StrSQL=StrSQL &"'" &them_FAX&"',"
StrSQL=StrSQL &"'" &them_ghichu&"'" ‘CHÚ Ý TR NG CU IƯỜ Ố
StrSQL=StrSQL &");"
On Error Resume next
Dim rstin
Set rstin=objCn.Execute(StrSQL)
If Err<>0 Then
Response.Write("<p align=center><font color=red><b>Co Loi khi them du lieu<p>")
Else
Response.Write("<p align=center><font color=red><b>Them DL thanh cong<p><BR>")
Response.Write("<A HREF=""xuat_ds_dienthoai.asp"">Tro lai trang danh ba</A>")
END IF
ELSE
End If
%>
Chú ý không có
kho ng tr ng ả ố
gi a các tr ngữ ườ
4.T O M T TRANG WEB B T KỲ XÓA THÔNG TIN TRONG CSDLẠ Ộ Ấ
Ví d :ụ T o trang web xoá thông tin đ c ch n trên danh sách danh b ạ ượ ọ ạ
l u l i v i tên ư ạ ớ xoa_ds_dienthoai.asp
L y thông tin c n xóa t trang ấ ầ ừ xuat_ds_dienthoai.asp
• Xem l i trang xu t danh sách đi n tho i trên ạ ấ ệ ạ ở C T CH C NĂNGỘ Ứ
response.Write"<a href='xoa_ds_dienthoai.asp?xoadienthoai="&rs("STT")&"'> Xoá |</a>"
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!---#include file="ketnoicosodulieu.asp"---->
<%
madbcanxoa=Request.QueryString("xoadienthoai")
StrSQL="DELETE FROM danhba WHERE cSTR([STT])='"&madbcanxoa&"';"
set RS = objCn.Execute(StrSQL)
Response.Redirect("xuat_ds_dienthoai.asp")
%>