seeyouagain古筝视频:求ACCESS中的进货录入窗体的代码、出货窗体的代码和查询修改窗体的代码

来源:百度文库 编辑:中科新闻网 时间:2024/05/14 00:17:01

我有一个关于学生的管理的代码,类型很接近,你可以效仿:
1.插入一条记录
<% '打开数据库连接
dim xh,xm,zym,xb,cssj,zxf,bz
xh=request("xh")
xm=request("xm")
zym=request("zym")
xb=request("xb")
cssj=request("cssj")
zxf=request("zxf")
bz=request("bz")

'打开连接
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")
conn.open

'查找该学号是否在数据库中已经存在
dim rs
set rs=conn.execute("select * from student where xh='" & xh & "'")
if not(rs.eof and rs.bof) then'记录集不空
rs.close
conn.close
%>
<p>该学号的数据已经存在,不能入库!请返回重新填写!!! </p>
<p><input type="button" value="返回" onClick="vbscript:history.back()"> </p>
<% response.end%>
<% else '记录集空
dim str
str="insert into student(xh,xm,zym,xb,cssj,zxf,bz) values ('" & xh & "','" & xm & "','" & zym & "','" & xb & "',#" & cssj & "#," & zxf & ",'" & bz & "')"
response.write "<font size=""5"" color='#FF0000'>" & str & "</font>"
rs.close
conn.execute(str)
conn.close
%>

<P>恭喜,您的数据顺利入库!</P>
<p><input type="button" value="返回" onClick="vbscript:history.back()"></p>
<% end if %>
2.查询
<center><h1>所有学生列表</h1></center>
<%
'第一步:创建数据库连接对象
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")
conn.open
'第二步:创建查询记录集
dim rs
dim sqlstr
sqlstr="select * from student"
set rs=conn.execute(sqlstr)
'第三步:循环取出所有记录并显示
%>

<table width="100%" border="1" cellspacing="0">
<tr>
<td>学号</td>
<td>姓名</td>
<td>专业名</td>
<td>性别</td>
<td>出生日期</td>
<td>总学分</td>
<td>备注</td>
<td colspan="3"><center>选择点击</center></td>
</tr>
<% while rs.eof=false %>
<!-- 同上结果<% ' while not rs.eof %> -->
<tr>
<td><% response.write rs("xh") %></td>
<td><% response.write rs("xm") %></td>
<td><% response.write rs("zym") %></td>
<td><% response.write rs("xb") %></td>
<td><% response.write rs("cssj") %></td>
<td><% response.write rs("zxf") %></td>
<td><% response.write rs("bz") & " " %></td>
<td><a onClick="sub1(<%=rs("xh")%>)" href="#">删除</a></td>
<td><a href="update.asp?xh=<%=rs("xh")%>">修改</a></td>
</tr>
<% rs.movenext
wend %>
<% '第四步:关闭记录集和数据库连接
rs.close
conn.close
%>
<h1>查询结果</h1>
<%
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")
conn.open

dim rs
dim sqlstr
sqlstr="select * from student where xh='" & request("xh") & "'"
set rs=conn.execute(sqlstr)

if rs.eof and rs.bof then '空
rs.close
conn.close
%>
<p>没有该学员信息!!!</p>
<p><input type="button" value="返回" onClick="vbscript:history.back"></p>
<% else %>
<br>
<p>学号: <% =rs("xh") %></p>
<p>姓名:<% =rs("xm") %></p>
<p>专业名:<% =rs("zym") %></p>
<p>性别:<% =rs("xb") %></p>
<p>出生时间:<% =rs("cssj") %></p>
<p>总学分:<% =rs("zxf") %></p>
<p>备注:<% =rs("bz") %></p>
<p><input type="button" value="返回" onClick="vbscript:history.back"></p>

<% rs.close
conn.close
end if
%>

3.修改学生信息
<h1>修改<%=request("xh")%>学生信息</h1></center>
<%
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")
conn.open

dim rs
set rs=conn.execute("select * from student where xh='" & request("xh") & "'")
if rs.eof and rs.bof then
rs.close
conn.close
%>
<p>没有该学生信息!</p>
<p><input type="button" value="返回" onClick="vbscript:history.back"></p>
<% response.end%>
<% else %>
<form name="form1" method="post" action="update1.asp">
<p>学号:<%=rs("xh")%></p>
<p>姓名:<input type="text" name="xm" value="<%=rs("xm")%>"></p>
<p>专业名:<input type="text" name="zym" value="<%=rs("zym")%>"></p>
<p>性别:<input type="text" name="xb" value="<%=rs("xb")%>"></p>
<p>出生时间:<input type="text" name="cssj" value="<%=rs("cssj")%>"></p>
<p>总学分:<input type="text" name="zxf" value="<%=rs("zxf")%>"></p>
<p>备注:<input type="text" name="bz" value="<%=rs("bz")%>" ></p>
<p><input type="submit" name="submit" value="保存"><input type="reset" name="reset" value="重填"></p>
</form>
<% rs.close
conn.close
%>
<% end if %>
<% '
dim xh,xm,zym,xb,cssj,zxf,bz
xh=request("xh")
xm=request("xm")
zym=request("zym")
xb=request("xb")
cssj=request("cssj")
zxf=request("zxf")
bz=request("bz")

'打开连接
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")'
conn.open
conn.execute("update student set xm='" & xm & "',zym='" & zym & "',xb='" & xb & "',cssj='" & cssj & "',zxf='" & zxf & "',bz='" & bz & "' where xh='" & xh & "'")
conn.close
%>
<P>恭喜,您的数据保存成功!@!</P>
<p><input type="button" value="返回" onClick="vbscript:location.href='list.asp'"> </p>

4.删除信息
<%
dim conn
set conn=Server.CreateObject("ADODB.connection")
conn.connectionstring=application("connstr")
conn.open
dim sqlstr
sqlstr="delete from student where xh='" & request("xh") & "'"
conn.execute sqlstr
conn.close
%>
<center>
<h1>成功删除!</h1>
<p><input type="button" value="返回" onClick="vbscript:location.href='list.asp'"></p>
</center>

注意:global.asa文件的数据库连接 你可以根据字段名称从建一个数据库(access类型)

Sub Application_OnStart
'Application("connstr")="driver=sql server;server=192.168.1.199;database=datatest;uid=sa;pwd="
Application("connstr")="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\yangxin\yangxin.mdb;Persist Security Info=False"
End Sub