這裏是我的代碼:Visual Basic:無法從記錄集中讀取記錄/數據。
Dim CompanyName, _
CompanyDomain, _
CompanyEmail, _
CompanySupportPhone
Call GetEmailList
Sub GetEmailList
dim sql
dim companydata
sql = ""
sql = sql & " DECLARE @CompanyName VARCHAR(100);"
sql = sql & " DECLARE @CompanyDomain VARCHAR(100);"
sql = sql & " DECLARE @CompanyActivityEmail VARCHAR(100);"
sql = sql & " DECLARE @CompanySupportPhone VARCHAR(100);"
sql = sql & " SELECT"
sql = sql & " @CompanyName = CASE WHEN Setting = 'CompanyName'"
sql = sql & " THEN StringValue ELSE @CompanyName END,"
sql = sql & " @CompanyDomain = CASE WHEN Setting = 'CompanyDomain'"
sql = sql & " THEN StringValue ELSE @CompanyDomain END,"
sql = sql & " @CompanyActivityEmail = CASE WHEN Setting = 'CompanyActivityEmail'"
sql = sql & " THEN StringValue ELSE @CompanyActivityEmail END,"
sql = sql & " @CompanySupportPhone = CASE WHEN Setting = 'CompanySupportPhone'"
sql = sql & " THEN StringValue ELSE @CompanySupportPhone END"
sql = sql & " FROM ClientSettings"
sql = sql & " WHERE Setting in ('CompanyDomain','CompanyActivityEmail','CompanySupportPhone','CompanyName')"
sql = sql & " SELECT ISNULL(@CompanyName, '') AS CompanyName, ISNULL(@CompanyDomain, '') AS CompanyDomain, ISNULL(@CompanyActivityEmail, '') AS CompanyEmail, ISNULL(@CompanySupportPhone, '') AS CompanySupportPhone"
set companydata = getRecordset(sql)
CompanyName = companydata("CompanyName") ' LINE 80
CompanyDomain = companydata("CompanyDomain")
CompanyEmail = companydata("CompanyEmail")
CompanySupportPhone = companydata("CompanySupportPhone")
companydata.Close
Set companydata = Nothing
End Sub
這將引發一個錯誤:
Line 80
Item cannot be found in the collection corresponding to the requested name or ordinal.
我上面標線80。我在SQL Server管理器中運行完全相同的SQL並返回結果:
CompanyName CompanyDomain CompanyEmail CompanySupportPhone
MyCompanyName http://localhost [email protected] 801-555-1212
任何想法我在做什麼錯在這裏?
GetRecordSet正確加載和處理數據庫調用,該函數可以在其他1,000個地方使用。我相信這個問題不存在。
請爲您的問題選擇一個更具描述性的標題。 「我在使用Visual Basic遇到問題」......誰不是? – 2012-04-06 18:46:22