1

我正在使用 sql server 和 asp classic,目前正在调用这样的查询:

newHireSQL = "select * from NewHire where Archived = 0 order by HireID desc"

Set rsGetHireID = Server.CreateObject("ADODB.Recordset")
rsGetHireID.Open newHireSQL,ConnectionString,adOpenStatic

NumOfHireID = rsGetHireID.RecordCount

但我不想在这里使用查询语句,而是调用一个名为dbo.sp_selectNewHireSQL. 我怎样才能做到这一点?

谢谢

编辑:

我试过这个

Dim Conn
SET Conn = Server.CreateObject("ADODB.Connection")
SET rsGetHireID = Server.CreateObject("ADODB.RecordSet")
Conn.Open ConnectionString
set rsGetHireID=Conn.Execute("Exec sp_selectNewHireSQL")

NumOfHireID = rsGetHireID.RecordCount
Response.Write (NumOfHireID)

但我得到了-1记录数的价值。

4

4 回答 4

4

它只是使用execexecute声明:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnectionString
Conn.Execute "Exec sp_selectNewHireSQL"

参考: http: //msdn.microsoft.com/en-us/library/ms188332 (v=sql.90).aspx

于 2013-05-09T18:50:18.797 回答
3

要使 RecordCount 工作,您需要使用正确的游标:

Set rsGetHireID = Server.CreateObject("ADODB.RecordSet")
Conn.Open ConnectionString
rsGetHireID.CursorLocation = 3 'adUseClient
rsGetHireID.Open "Exec sp_selectNewHireSQL", Conn
NumOfHireID = rsGetHireID.RecordCount
于 2013-05-12T07:10:29.197 回答
0

而不是 using ADODB.Connection,而是尝试ADODB.Command像这样使用:

        Set objCommand = Server.CreateObject("ADODB.Command")
        objCommand.ActiveConnection = ConnectionString
        objCommand.CommandText = "dbo.sp_selectNewHireSQL"
        objCommand.CommandType = adCmdStoredProc ' you have to include adovbs.inc file or you can use 4

        Set rsGetHireID = objCommand.Execute()
        NumOfHireID = rsGetHireID.RecordCount
        Response.Write (NumOfHireID)    
于 2015-03-14T01:31:21.997 回答
-4
<%


    dim db_conn

   db_conn = "Provider=SQLOLEDB.1;Server=server name;Database=dbname;Uid=sa; Pwd=123;"
set conn = server.createobject("adodb.connection")
set Cmd = Server.CreateObject("ADODB.Command")
'-------------------------------------------------------
conn.open (db_conn)
'-------------------------------------------------------
set rs = Server.CreateObject("ADODB.RecordSet")  
sSQL = "EXEC sp_countrylist @countryname ='" & countryname & "'"
set rs = conn.execute(sSQL) 

if (rs.bof and rs.eof) then
    response.Write "<span class=""error"">No Record Found</span>"
    response.End
end if %>
于 2013-12-06T06:33:05.770 回答