注册 登录
编程论坛 ASP技术论坛

将一个注册表单的数据写入两个数据库。

wwm123456789 发布于 2015-01-15 20:58, 2902 次点击
程序代码:
<!-- #include file = "../common/site.inc" -->
<%
dim StudentID,name,teacher
StudentID
=request.form("StudentID")

 name
=request.form("name")

 teacher
=request.form("teacher")

 
set rs=server.createobject("adodb.recordset")

 sql
="select StudentID,name,password,teacher,ph,sfz,bmsj from student where StudentID='"&StudentID&"'"

 rs.open sql,cn,
1,1

 
if rs.eof then
  response.write
"<script>alert('您的学号不存在!');history.back();</script>"
  response.end
  
else
   
if rs("name")<>name then
      response.write
"<script>alert('您的名字与你的学号不匹配!');history.back();</script>"
      response.end
      
else
      
if rs("password")<>"" then
      response.write
"<script>alert('您已经注册,请直接登陆!');history.back();</script>"
      response.end
      
else
   
if rs("teacher")<>teacher then
      response.write
"<script>alert('您的任课教师填写错误!');history.back();</script>"
      response.end
     
end if
     
end if  
     
end if
     
end if  
%>
<%
set rs=server.createobject("adodb.recordset")
sql
="select StudentID,name,password,teacher,ph,sfz,bmsj from student where StudentID='"&StudentID&"'"
rs.open sql,cn,
1,3
name
=request.form("name")
password
=request.form("password2")
teacher
=request.form("teacher")
ph
=request.form("ph")
sfz
=request.form("sfz")
bmsj
=request.form("bmsj")
rs(
"name")=name
rs(
"password")=password
rs(
"teacher")=teacher
rs(
"ph")=ph
rs(
"sfz")=sfz
rs(
"bmsj")=bmsj
rs.update
rs.close
set rs=nothing
cn.close
set rs=nothing
response.write
"<script>alert('注册成功,请登陆!');location.href='logon.asp'</script>"
%>
这是将注册信息写入其中一个数据库,如果想同时写入另一个数据库,程序上应该怎么写呢,两个数据库结构和表是一样的,谢谢。
4 回复
#2
ysf01812015-01-16 14:58
说明,你对对象理解不深。

在创建一个连接数据库的对象就可以了。

sql="select StudentID,name,password,teacher,ph,sfz,bmsj from student where StudentID='"&StudentID&"'"
rs.open sql,cn,1,3


sql="select StudentID,name,password,teacher,ph,sfz,bmsj from student where StudentID='"&StudentID&"'"
rs.open sql,cn1111,1,3

再次执行代码。
#3
hu9jj2015-01-16 21:13
建立多个连接,分别连接多个数据库,就可以对多个数据库(表)进行操作了。
#4
tlliqi2015-01-16 21:56
会一个 就会二个
#5
kingfangden2015-01-17 21:29
学习了。
1