Lm th? no ? g?i cho my ch? SQL lu tr? th? t?c t? ASP

D?ch tiu ? D?ch tiu ?
ID c?a bi: 164485 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

TM T?T

?i v?i m?t Microsoft Visual Basic.NET Phin b?n c?a bi vi?t ny, xem 306574.
Bi vi?t ny ch?ng t? ba phng php c?a ku g?i m?t th? t?c ?c lu tr? t? cc trang ph?c v? ho?t ?ng b?ng cch s? d?ng ActiveX Data Objects (ADO).

THNG TIN THM

V d? sau s? d?ng l?nh ?i t?ng ? g?i m?t m?u lu tr? th? t?c sp_test. Th? t?c ?c lu tr? ny ch?p nh?n m?t s? nguyn v c gi tr? tr? l?i b?ng m?t s? nguyn l t?t:
   <%@ LANGUAGE="VBSCRIPT" %>
   <!--#include virtual="/ASPSAMP/SAMPLES/ADOVBS.INC"-->
   <HTML>
   <HEAD><TITLE>Place Document Title Here</TITLE></HEAD>
   <BODY>
   This first method queries the data source about the parameters
   of the stored procedure. This is the least efficient method of calling
   a stored procedure.<BR>
   <%
   Set cn = Server.CreateObject("ADODB.Connection")
   Set cmd = Server.CreateObject("ADODB.Command")
   cn.Open "data source name", "userid", "password"
   Set cmd.ActiveConnection = cn
   cmd.CommandText = "sp_test"
   cmd.CommandType = adCmdStoredProc
   ' Ask the server about the parameters for the stored proc
   cmd.Parameters.Refresh
   ' Assign a value to the 2nd parameter.
   ' Index of 0 represents first parameter.
   cmd.Parameters(1) = 11
   cmd.Execute
   %>
   Calling via method 1<BR>
   ReturnValue = <% Response.Write cmd.Parameters(0) %><P>

   <!-- ************************************************************ -->

   Method 2 declares the stored procedure, and then explicitly declares
   the parameters.<BR>
   <%
   Set cn = Server.CreateObject("ADODB.Connection")
   cn.Open "data source name", "userid", "password"
   Set cmd = Server.CreateObject("ADODB.Command")
   Set cmd.ActiveConnection = cn
   cmd.CommandText = "sp_test"
   cmd.CommandType = adCmdStoredProc
   cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _
      adParamReturnValue)
   cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
      adParamInput)
   ' Set value of Param1 of the default collection to 22
   cmd("Param1") = 22
   cmd.Execute
   %>
   Calling via method 2<BR>
   ReturnValue = <% Response.Write cmd(0) %><P>

   <!-- ************************************************************ -->

   Method 3 is probably the most formal way of calling a stored procedure.
   It uses the canocial
   <%
   Set cn = Server.CreateObject("ADODB.Connection")
   cn.Open "data source name", "userid", "password"
   Set cmd = Server.CreateObject("ADODB.Command")
   Set cmd.ActiveConnection = cn
   ' Define the stored procedure's inputs and outputs
   ' Question marks act as placeholders for each parameter for the
   ' stored procedure
   cmd.CommandText = "{?=call sp_test(?)}"
   ' specify parameter info 1 by 1 in the order of the question marks
   ' specified when we defined the stored procedure
   cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _
   adParamReturnValue)
   cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _
     adParamInput)
   cmd.Parameters("Param1") = 33
   cmd.Execute
   %>
   Calling via method 3<BR>
   ReturnValue = <% Response.Write cmd("RetVal") %><P>
   </BODY>
   </HTML>
				
Lu ? trong cc v d? ? trn, cc phng php c?a vi?c truy c?p cc thng s? b? su t?p c?a cc ?i t?ng l?nh ?c s? d?ng. M?t s? s? d?ng b? su t?p m?c ?nh c?a ?i t?ng l?nh trong khi nh?ng ng?i khc ch? ra nh?ng g? thu?c tnh c?a m?t t?p h?p nh?t ?nh ? truy c?p.

THAM KH?O

Cho bi vi?t c s? ki?n th?c m?i nh?t v cc h? tr? thng tin v? th? gic InterDev v Active Server Pages, xem trang sau trn trang web h? tr? k? thu?t c?a Microsoft:
http://support.Microsoft.com/Search/Default.aspx?qu=vinterdev

Thu?c tnh

ID c?a bi: 164485 - L?n xem xt sau cng: 19 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Active Server Pages 4.0
  • Microsoft ActiveX Data Objects 2.7
T? kha:
kbcode kbdatabase kbhowto kbsample kbscript kbmt KB164485 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:164485
Khc t Ni dung trong C s Kin thc Khng con c h tr
Bi vi?t ny ni v? cc s?n ph?m m Microsoft khng c?n h? tr? n?a. Do , bi vi?t ny ?c cung c?p "nguyn b?n" v s? khng ?c c?p nh?t.

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com