1.关于数据库操作的公用程序
<%
Dim g_conn,g_strConn
Dim g_strSQLServerName
Dim g_strSQLDBUserName
Dim g_strSQLDBPassword
Dim g_strSQLDBName
g_strSQLServerName=”(local)”
g_strSQLDBUserName=”sa”
g_strSQLDBPassword=””
g_strSQLDBName=”BookStore”
Set g_conn=Server.CreateObject(“ADODB.Connection”)
g_strConn=”Provider=SQLOLEDB.1;Persist Security Info=False;Server=”& g_strSQLServerName &”;User ID=”& g_strSQLDBUserName &”;Password=”& g_strSQLDBPassword &”;Database=”& g_strSQLDBName &”;”g_conn.Open g_strConn
Function CloseDatabase
g_conn.Close
Set g_conn=Noting
End Funtion
Function GetRecordset(strSQL,intOpenType)
Dim rs
Set rs=CreateObject(“ADODB.Recordset”)
Select Case intOpenType
Case 0
rs.Open strSQL,g_conn,0,1
Case 1
rs.Open strSQL,g_conn,1,3
End Select
Set GetRecordset=rs
End Function
Function GetRecordsetWithID(strTableName,intID,intOpenType)
Dim strSQL
strSQL=”Select*From”&strTableName&”Where ID=”&intID
Set GetRecordsetWithID=GetRecordset(strSQL,intOpenType)
End Function
Function IsExistStringValue(strTableName,strField,strValue)
Dim strSQL,rs
strSQL=”Select count(*) sa count From”&strTableName&”Where”&strField&”=”&strValue&””Set rs=GetRecordset(strSQL,0)
If rs(“count”).Value=0 Then
IsExistStringValue=Fasle
Else
IsExistStringValue=Ture
End If
Set rs=Nothing
End Function
Function IsExistStringValueWithoutID(strTableName,strField,strValue,intID)
Dim strSQL,rs
strSQL=”Select count(*)as count
From”&strTableName&”Where”&strField&”=”strValue&””&”And ID<>”&intID
Set rs=GetRecordset(strSQL,0)
If rs(“count”).Value=0 Then
IsExistStringValueWithoutID=False
Else
IsExistStringValueWithoutID=Ture
End If
End Function
Function DeleteWithID(strTable,intID)
Dim strSQL
strSQL=”Delete”&strTable&”Where ID=”&intID
g_conn.Execute strSQL
End Function
%>
2.用户登录的实现
<%
Dim strUserName,strPassword,strNickName,bolLogonSuccess
strUserName=FormatString(Request.Form(“UserName”))
strPassword=FormatString(Request.Form(“Password”))
Dim rs,strSQL
strSQL=”Select NickName From UserInfo Where”
strSQL=strSQL&”UserName=’”&strUserName&”’And Password=’”&strPassword&”’”Set rs=GetPecordset(strSQl,1)
bolLogonSuccess=False
If rs.RecordCount>0 Then
strNickName=rs(“NickName”).Value
Session(“UserName”)=strUserName
bolLogonSuccess=Ture
End If
Set rs=Nothing
CloseDataBase
%>
用户名:<%=Section(“UserName”)%> 昵称: <%=strNickName%> |
登陆成功! |
用户名或密码错误! |