2011-12-15 117 views
0

我想知道如何將SQL查詢的結果分配給變量。將sql查詢的結果存儲到變量中

我有下面的查詢:

set userid = Server.CreateObject("adodb.recordset") 

user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'" 

userid.Open query,OLSLive,1,3 

和我想分配查詢的結果,使我可以將它作爲一個參數的存儲過程。

+0

你在VB中是什麼意思? – 2011-12-15 13:04:22

回答

0

假設一個值預計會返回,您只需要讀取記錄集第一個值;

userid.Open query,OLSLive,1,3 
if not userid.eof then 'check for rows 
    your_variable = userid.collect(0) 'read 1st column, 1st row 
    ... 
else 
    'no matching row 
0

我要去猜測,這是VBScript中......

userID.Open query,OSLive,1,3 

if not userID.eof then 
    variableNamedSomething = recordset("id") 
else 
    ' something else 
end if 
'... get rid of the connection 
userID.Close 
set userID = nothing 
OSLive.Close 
set OSLive = nothing 
+0

對不起,我的回答和其他的一樣......我在輸入時輸入了另一個。注意:...我更喜歡使用經典的ASP序列中的列名collect(0)使得可讀性不如彙集(「id」)將是...也不要忘記當你是關閉你的記錄集做... – 2011-12-15 13:11:31

相關問題