我使用一個存儲過程,FilterExpressionsASP.NET的SqlDataSource預計FilterExpression列在存儲過程
建築的搜索結果轉發只希望用戶3 SELECT語句或在我的中繼器4列但在我的where語句中可能有幾個不同的查詢。
我的存儲過程會是這個樣子
Select organisationRegulatory.ID,
organisationRegulatory.name As regname,
regAddr1, regAddr2, regAddr3, regAddr4, regAddr5,
CRONumber,
CHYNumber,
legalObjects,
charityActCategoryID,
isprimary,
organisationVoluntary.overviewURL As overviewURL,
min(targetCommunityId) as targetCommunityId
from organisationRegulatory
inner join organisationVoluntary
on organisationRegulatory.ID = organisationVoluntary.ID
left outer join targetCommunitiesToOrganisation
on organisationRegulatory.ID = targetCommunitiesToOrganisation.ID
left outer join charityActCategoriesToOrganisation
on organisationRegulatory.ID = charityActCategoriesToOrganisation.ID
left outer join financial
on organisationRegulatory.ID = financial.ID
where organisationVoluntary.publishStatusID = 2
Group BY organisationRegulatory.ID,
regAddr1,regAddr2,regAddr3,regAddr4,regAddr5,
CRONumber,
CHYNumber,
legalObjects,
organisationRegulatory.name,
organisationVoluntary.overviewURL,
nameCompSecretary,
charityActCategoryID,
isPrimary,
overviewURL
order by ID
我的過濾器表達可能是這個樣子
AND (value > 50000 AND financialActivityTypeID = 31) AND (isPrimary = 1 AND charityActCategoryID = 1)
如果我添加篩選表達式中的WHERE子句中的SQL通常我得到預期的結果,但如果我嘗試通過
SqlDataSource1.FilterExpression = "AND (value > 50000 AND financialActivityTypeID = 31) AND (isPrimary = 1 AND charityActCategoryID = 1)";
將篩選表達式添加到Stpred Procedure
我得到一個錯誤,
Exception Details: System.Data.EvaluateException: Cannot find column [financialActivityTypeId].
,直到我那列添加到SQL查詢的SELECT語句,我不想這樣做,因爲它會減慢查詢很大。有可能解決這個問題嗎?
這裏的中繼
<asp:Repeater
id="rptSearchResults"
runat="server"
DataSourceID="SqlDataSource1"
onitemdatabound="Repeater1_ItemDataBound">
和這裏的SQL數據源
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"
SelectCommand="spGetSearchResults"
SelectCommandType="StoredProcedure"
>
</asp:SqlDataSource>
任何幫助將非常感激。
感謝
太好了,謝謝。 我以爲聚合函數是導致速度問題的原因......我現在就試試這個,謝謝。 –