StoredProcedure在企业网站开发中的应用(2)

StoredProcedure在企业级网站开发中的应用(二)
Writen by pepper_dog999
第五步:在前台调用该StoredProcedure,这里我们用ADO对象的Command,程序如下:

 1   
 2const adCmdStoredProcedure=&H0004   
 3const adChar=129   
 4const adParamInput=&H0001   
 5set conn=server.CreateObject("ADODB.Connection")   
 6set comm=server.CreateObject("ADODB.Command")   
 7conn.ConnectionString="Driver={SQL Server};Server=WKS1;"& _   
 8"uid=db_user;pwd=;database=testdb;"   
 9conn.open   
10comm.ActiveConnection=conn   
11comm.CommandType=adCmdStoredProcedure   
12comm.CommandText="usp_add_info"   
13set param=comm.CreateParameter(LN,adChar,adParamInput,20)   
14param.value=request.form("LastName")   
15comm.parameters.append param   
16set param=comm.CreateParameter(FN,adChar,adParamInput,20)   
17param.value= request.form("FirstName")   
18comm.parameters.append param   
19set param=comm.CreateParameter(AD,adChar,adParamInput,255)   
20param.value= request.form("Address")   
21comm.parameters.append param   
22comm.execute   
23conn.close   

使用这种方法我们就可以将数据库的主体开发工作转到数据库服务器上,而在前台只是一个简单的调用过程和参数的传递过程。在性能、安全性等方面有极好的应用,大家可以在数据库服务器上开发出很多十分复杂的应用来

Published At
Categories with Web编程
Tagged with
comments powered by Disqus