日期:2014-05-17  浏览次数:20748 次

求助:关于asp以及数据库的应用的问题,大家帮帮忙啊~~!在线等
想要把如下代码中的2个函数(Sub WriteSub()和sub addstaf())整合一下,其中第一个函数是点击增加按钮可以将用户名存入数据表DocManageTypeTable中,第2个函数是点击增加按钮可以将用户的一系列基本信息存入数据表userinf中,自己整合了好久总是只能实现一个效果,麻烦各位大虾们帮忙看看啊,跪求解答~!
<%
Public Conn,username,ID,ReturnValue
on error resume next
Sub ErrorSub()
Conn.Close
Set Conn=Nothing
Response.Write("</body></html>")
End Sub
function strlength(inputstr)
dim length,i
length=0
for i=1 to len(inputstr)
if asc(mid(inputstr,i,1))<0 then
length=length+2
else
length=length+1
end if
next
strlength=length
end function
Sub WriteSub(SqlStr,SqlStr1)
ReturnValue=True
If strlength(username)>50 Or username="" Then
Call DispErrorInfo1("对不起,用户名太长,不能超过25汉字且不能为空!")
Call ErrorSub
ReturnValue=False
Else
Set Rs=Server.CreateObject("Adodb.RecordSet")
Rs.Open SqlStr,Conn,1
If Rs.Eof And Rs.Bof Then
Conn.Execute(SqlStr1)
If Err.Number<>0 Then
Conn.RollbackTrans
Call DispErrorInfo1("对不起,增加用户名太长!错误原因:" & Err.Description)
Rs.Close
Set Rs=Nothing
Call ErrorSub
ReturnValue=False
Else
Conn.CommitTrans
End If
Else
Rs.Close
Set Rs=Nothing
Call ErrorSub
Call DispErrorInfo1("对不起,该用户已经存在,请重新输入!")
ReturnValue=False
response.end
End If
End If
End Sub
'On Error Resume Next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "dbq="&server.mappath("./Doc_Storeroom/DocData")&";driver={microsoft access driver (*.mdb)};"
Conn.BeginTrans
username=Trim(Request.Form("username"))
ID=CutRequestString(Request.Form("IDValue"))
If Request.Form("submit")=" 增加 " Then
Call WriteSub("Select * From DocManageTypeTable Where DocType='" & username & "'","Insert Into DocManageTypeTable (DocType) Values('" & username & "')")
If Not ReturnValue Then
Response.End
End If
Conn.CommitTrans
End If
%>
<%
sub addstaf(href)
oabusyuserdept=request.cookies("oabusyuserdept")
if request("submit")="增加" then
errorinfo=""
username=request("username")
if strlength(username)>10 then
errorinfo=errorinfo&"用户名太长,不能超过5个汉字或10个英文字符!<br>"
end if
password=request("password")
if strlength(password)>20 then
errorinfo=errorinfo&"密码太长,不能超过20个字符!<br>"
end if
name=request("name")
if strlength(name)>10 then
errorinfo=errorinfo&"姓名太长,不能超过5个汉字或10个英文字符!<br>"
end if
userdept=request("userdept")
if strlength(userdept)>10 then
errorinfo=errorinfo&"联系方式太长,不能超过5个汉字或10个英文字符!<br>"
end if
userlevel=request("userlevel")
if strlength(userlevel)>10 then
errorinfo=errorinfo&"工作单位太长,不能超过5个汉字或10个英文字符!<br>"
end if
if errorinfo="" then
'判断是否有与申请的用户名相同的
on error resume next
set conn=opendb("oabusy","conn","accessdsn")
conn.begintrans
set rs2=server.createobject("adodb.recordset")
password=md5(password)
sql2="select * from userinf where username=" & sqlstr2(username) & " or password=" & sqlstr2(password)
rs2.open sql2,conn,1
if not rs2.eof and not rs2.bof then
%>
<center><font color="red"