1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Bài thực hành số 6: ADO, Phân trang với Recordseự doc

9 488 1
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Bài thực hành số 6: ADO, Phân trang với Recordset
Tác giả Lê Anh Tú
Trường học Đại Học Thái Nguyên
Chuyên ngành Mạng & Truyền thông
Thể loại Bài thực hành
Thành phố Thái Nguyên
Định dạng
Số trang 9
Dung lượng 417,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Thiết kế trang DEFAULT.ASP cho phép hiển thị các thông tin về sinh viên như sau: Chú ý: - Sử dụng kỹ thuật phân trang - Các chức năng ADD, EDIT, DELETE để thực hiên các chức năng thêm mớ

Trang 1

1 Tạo CSDL HOSO.MDB và thiết kế các bảng dữ liệu có cấu trúc như sau:

Tạo quan hệ giữa 2 bảng như sau:

2 Thiết kế trang DEFAULT.ASP cho phép hiển thị các thông tin về sinh viên như sau:

Chú ý:

- Sử dụng kỹ thuật phân trang

- Các chức năng ADD, EDIT, DELETE để thực hiên các chức năng thêm mới, sửa, xóa các bản ghi

- Nhấn vào Mã SV cho phép liên kết đến trang xem tổng hợp thông tin cá nhân về SV đó (Ví dụ: Profile.asp)

Bảng Sinhvien

Bảng Tinh

Trang 2

3 Yêu cầu thiết giao diện các trang thêm mới và sửa như sau:

- Giao diện cập nhật SV mới

- Giao diện thay đổi thông tin cá nhân 1 SV đã nhập

MÃ NGUỒN MẦU

File Connection.inc

<%

FilePath=Server.Mappath("Hoso.mdb")

Set Conn=Server.CreateObject("ADODB.COnnection")

StrConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath

Conn.Open strConn

Set RS=Server.CreateObject("ADODB.Recordset")

%>

File Default.asp

<! #include file=Connection.inc >

<%

'Su dung Query trong Access de tao xau truy van nhu duoi day

StrSQL="SELECT SinhVien.*, [Tinh].[Tentinh] FROM Tinh INNER JOIN SinhVien ON [Tinh]

[MaTinh]=[SinhVien].[MaTinh];"

'Dat thuoc tinh cho RS co kha nang phan trang

RS.CursorLocation=3

RS.Pagesize=3

RS.Open StrSQL,Conn,0,1

'Xac dinh trang hien thoi

Session("CurrenPage")=1

If request("PageID")<>"" then

Session("CurrenPage")=Cint(request("PageID"))

End if

Trang 3

If not(RS.eof or RS.bof) then

RS.Absolutepage=Session("CurrenPage")

End if

%>

<html>

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 6.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>Phân trang với RS</title>

</head>

<body>

<p align="center"><b>DANH SACH SINH VIEN </b></p>

<form method="POST" action="Xuly_Default.asp">

<b>Page <%=Session("CurrenPage")%> of <%=RS.PageCount%></b>

<table border="0" width="100%">

<tr>

<td>STT</td>

<td>Sửa</td>

<td>Xóa</td>

<td>Mã SV</td>

<td>Họ và tên</td>

<td>Giới tính</td>

<td>Tuổi</td>

<td>Ngày vào đoàn</td>

<td>Tên Tỉnh</td>

<td>Sở thích</td>

</tr>

<%

i=RS.Pagesize*(Session("CurrenPage")-1)

While not RS.eof and RS.AbsolutePage=Session("CurrenPage")

i=i+1

%>

<tr>

<td><%=i%></td>

<td><input type="radio" value=<%=RS.Fields("MaSV")%> checked name="RdoSua"></td> <td><input type="checkbox" name="chkXoa" value=<%=RS.Fields("MaSV")%>></td>

<td>

<a href=Profile.asp?MaSV_ID=<%=RS.Fields("MaSV")%>><%=RS.Fields("MaSV")%></a> </td>

<td><%=RS.Fields("Hoten")%></td>

<td width="6%" align="center">

<%

If RS.Fields("Gioitinh") then

Response.Write("Nam")

Else

Response.Write("Nu")

End if

%>

</td>

<td width="6%" align="center"><%=RS.Fields("Tuoi")%></td>

<td width="9%"><%=RS.Fields("NgayDoan")%></td>

<td width="10%"><%=RS.Fields("Tentinh")%></td>

<td width="29%"><%=RS.Fields("Sothich")%></td>

</tr>

Trang 4

RS.MoveNext

Wend

%>

</table>

<table border="0" width="100%">

<tr>

<td width="23%">

<%If Session("CurrenPage")=1 then

Response.write("Back")

Else%>

<a href=Default.asp?PageID=<%=Session("CurrenPage")-1%>>Back</a>

<%End if%>

</td>

<td width="54%">

<p align="center">

<%

k1=Session("CurrenPage")-1

k2=Session("CurrenPage")+1

If k1<1 then k1=1

If k2>RS.PageCount then k2=RS.PageCount

For i=k1 to k2

Response.write (" ")

If i=Session("CurrenPage") then

Response.write(i)

Else%>

<a href=Default.asp?PageID=<%=i%>><%=i%></a>

<%End if Next

%>

</td>

<td width="23%">

<p align="right">

<%If Session("CurrenPage")=RS.PageCount then

Response.write("Next")

Else%>

<a href=Default.asp?PageID=<%=Session("CurrenPage")+1%>>Next</a> <%End if

RS.Close

%>

</td>

</tr>

</table>

<input type="submit" value="Add" name="cmdAdd">

<input type="submit" value="Edit" name="cmdEdit">

<input type="submit" value="Delete" name="cmdDelete">

</form>

</body>

</html>

File Xuly_Default.asp

<%

if request.form("cmdAdd")<>"" then

response.redirect("Them.asp")

end if

if request.form("cmdEdit")<>"" then

session("MaSV")=request.form("rdoSua")

response.redirect("Sua.asp")

end if

Trang 5

if request.form("cmdDelete")<>"" then

%>

<! #include file=xoa.asp >

<%

end if

%>

File Them.asp

<! #include file=Connection.inc >

<%

StrSQL="Select * from Tinh Order By Tentinh"

RS.Open StrSQL,Conn

%>

<html>

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 6.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>Thêm mới SV</title>

</head>

<body>

<form method="POST" action="Xuly_them.asp">

<b>CẬP NHẬT SINH VIÊN</b>

<table border="0" width="61%">

<tr><td>Mã SV</td><input type="text" name="txtMaSV" size="12"></td></tr>

<tr><td>HỌ và tên</td><td><input type="text" name="txtHoten" size="30"></td></tr>

<tr>

<td>Giới tính</td>

<td><input type="radio" value="Nam" checked name="rdoGT">Nam

<input type="radio" name="rdoGT" value="Nu">Nữ

</td>

</tr> <tr><td>Tuổi</td><td><input type="text" name="txtTuoi" size="12"></td> </tr>

<tr> <td>Ngày vào đoàn</td>

<td>

<select size="1" name="optNgay">

<%For i=1 to 31%>

<option <%if i=day(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option> <%Next%>

</select>

<select size="1" name="optThang">

<%For i=1 to 12%>

<option <%if i=month(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option> <%Next%>

</select>

<select size="1" name="optNam">

<%For i=1970 to year(date())%>

<option selected value=<%=i%>><%=i%></option>

<%Next%>

</select></td>

</tr>

<tr>

<td>Tỉnh</td>

<td>

<select size="1" name="optTinh">

<%

While not Rs.eof

Trang 6

%>

<option value=<%=RS.Fields("Matinh")%>><%=RS.Fields("TenTinh")%></option>

<%

RS.MoveNext

Wend

RS.Close

%>

</select></td>

</tr>

<tr>

<td>Sở thích</td>

<td><input type="checkbox" name="chkST" value="Du lich">Du lịch

<input type="checkbox" name="chkST" value="The thao">Thể thao

<input type="checkbox" name="chkST" value="Xem TV">Xem TV

<input type="checkbox" name="chkST" value="Ca nhac">Ca nhạc

</td>

</tr>

<tr> <td><input type="submit" value="Save" name="CmdSave">

<input type="reset" value="Reset" name="cmdReset"></td>

</tr>

</table>

</form>

</body>

</html>

File Xuly_them.asp

<! #include file=Connection.inc >

<%

StrSQL="Select * from Sinhvien"

RS.Open StrSQL,Conn,1,3

RS.AddNew

RS.Fields("MaSV")=request.form("txtMaSV")

RS.Fields("Hoten")=request.form("txtHoten")

RS.Fields("MaSV")=request.form("txtMaSV")

If Request.form("rdoGT")="Nam" then

RS.Fields("Gioitinh")=True

else

RS.Fields("Gioitinh")=False

End if

RS.Fields("Tuoi")=request.form("txtTuoi")

ND=request.form("optThang")&"/"&request.form("optNgay")&"/"&request.form("optNam")

RS.Fields("NgayDoan")=Cdate(ND)

RS.Fields("Matinh")=request.form("optTinh")

RS.Fields("Sothich")=request.form("chkST")

RS.Update

RS.Close

response.redirect("Default.asp")

%>

File Sua.asp

<! #include file=Connection.inc >

<%

StrSQL="Select * from Tinh Order By Tentinh"

RS.Open StrSQL,Conn

StrSQL1="Select * from Sinhvien Where MaSV='" & session("MaSV") & "'"

Set RS1=Server.CreateObject("ADODB.Recordset")

RS1.Open StrSQL1,Conn

%>

Trang 7

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 6.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>Sửa thông tin SV</title>

</head>

<body>

<form method="POST" action="Xuly_Sua.asp">

<b>SUA THÔNG TIN SINH VIÊN</b>

<table border="0" width="61%">

<tr><td>Mã SV</td> <td><%=RS1.Fields("MaSV")%></td> </tr>

<tr>

<td>Họ và tên</td>

<td>

<input type="text" name="txtHoten" size="30" value=<%="'"&RS1.Fields("Hoten")&"'"%>> </td>

</tr>

<tr>

<td>Giới tính</td>

<td>

<input type="radio" value="Nam" <%if rs1.fields("Gioitinh") then%> checked <%End if%>

name="rdoGT">Nam

<input type="radio" name="rdoGT" <%if Not rs1.fields("Gioitinh") then%> checked <%End if%> value="Nu">Nữ

</td>

</tr>

<tr>

<td>Tuổi</td>

<td><input type="text" name="txtTuoi" size="12" value=<%=rs1.fields("Tuoi")%>></td>

</tr>

<tr>

<td>Ngày vào đoàn</td>

<td>

<select size="1" name="optNgay">

<%For i=1 to 31%>

<option <%if i=day(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><%=i

%></option>

<%Next%>

</select>

<select size="1" name="optThang">

<%For i=1 to 12%>

<option <%if i=Month(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><

%=i%></option>

<%Next%>

</select>

<select size="1" name="optNam">

<%For i=1970 to year(date())%>

<option <%if i=year(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><

%=i%></option>

<%Next%>

</select></td>

</tr>

<tr><td>Tỉnh</td>

<td>

Trang 8

<select size="1" name="optTinh">

<%

While not Rs.eof

%>

<option <%if RS.Fields("Matinh")=RS1.Fields("Matinh") then%> Selected <%End if%> value=<%=RS.Fields("Matinh")%>><%=RS.Fields("TenTinh")%></option>

<%

RS.MoveNext

Wend

%>

</select></td>

</tr>

<tr>

<td>Sở thích</td>

<td>

<input type="checkbox" name="chkST" value="Du lich" <%if

instr(Ucase(rs1.fields("Sothich")),ucase("Du lich"))>0 then%> checked <%End if%>>Du lịch

<input type="checkbox" name="chkST" value="The thao" <%if

instr(Ucase(rs1.fields("Sothich")),ucase("The thao"))>0 then%> checked <%End if%>>Thể thao

<input type="checkbox" name="chkST" value="Xem TV" <%if

instr(ucase(rs1.fields("Sothich")),ucase("Xem TV"))>0 then%> checked <%End if%>>Xem TV

<input type="checkbox" name="chkST" value="Ca nhac" <%if

instr(ucase(rs1.fields("Sothich")),ucase("Ca nhac"))>0 then%> checked <%End if%>>Ca nhạc</td> </tr>

<tr>

<td><input type="submit" value="Save" name="CmdSave">

<input type="reset" value="Reset" name="cmdReset">

</td>

</tr>

</table>

</form>

<%

rs.Close

rs1.Close

%>

</body>

</html>

File Xuly_sua.asp

<! #include file=Connection.inc >

<%

StrSQL="Select * from Sinhvien Where MaSV='" & session("MaSV") & "'"

RS.Open StrSQL,Conn,1,3

RS.Fields("Hoten")=request.form("txtHoten")

If Request.form("rdoGT")="Nam" then

RS.Fields("Gioitinh")=True

else

RS.Fields("Gioitinh")=False

End if

RS.Fields("Tuoi")=request.form("txtTuoi")

ND=request.form("optThang")&"/"&request.form("optNgay")&"/"&request.form("optNam")

RS.Fields("NgayDoan")=Cdate(ND)

RS.Fields("Matinh")=request.form("optTinh")

RS.Fields("Sothich")=request.form("chkST")

RS.Update

RS.Close

response.redirect("Default.asp")

%>

Trang 9

File Xoa.asp

<! #include file=Connection.inc >

<%

For i=1 to request.form("chkXoa").Count

If request.form("chkXoa")(i)<>"" then

StrSQL="Select * from SinhVien Where MaSV='" & request.form("chkXoa")(i) & "'" RS.Open StrSQL,Conn,1,3

RS.Delete RS.Close end if

next

Response.redirect("Default.asp")

%>

File Profile.asp

<! #include file=Connection.inc >

<%

StrSQL="SELECT SinhVien.*, Tinh.* FROM Tinh INNER JOIN SinhVien ON [Tinh]

[MaTinh]=[SinhVien].[MaTinh] WHERE MaSV=' " & request("MaSV_ID") & " ' “

RS.Open StrSQL,Conn

Response.write "Mã SV: " & RS.fields("MaSV") & "<BR>"

Response.write "Họ tên: " & RS.fields("Hoten") & "<BR>"

Response.write "Giới tính: "

If rs.fields("Gioitinh") then

Response.write "Nam" & "<BR>"

else

Response.write "Nữ" & "<BR>"

end if

Response.write "Tuổi: " & RS.fields("Tuoi") & "<BR>"

Response.write "Ngày vào đoàn: " & RS.fields("Ngaydoan") & "<BR>"

Response.write "Tỉnh/Tp: " & RS.fields("Tentinh") & "<BR>"

Response.write "Sở thích: " & RS.fields("Sothich") & "<BR>"

%>

<a href=Default.asp>Quay lại</a>

Yêu cầu SV hoàn thiện các phần thêm, sửa, xoá tỉnh

Ngày đăng: 25/12/2013, 23:18

HÌNH ẢNH LIÊN QUAN

Bảng Tinh - Tài liệu Bài thực hành số 6: ADO, Phân trang với Recordseự doc
ng Tinh (Trang 1)

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w