在我的代码后面我有一个函数getEmail(),返回一个电子邮件地址,在前端我有一个sql数据源selectcommand根据电子邮件地址获取信息。截至目前,电子邮件地址是硬编码的,我想知道如何将getEmail()放入select命令。使用VB函数作为SqlDataSource SelectParameter值
VB
Public Function getEmail() As String
Dim x As PublicProfile
x= UserProfileContext.Current.UserInfo
Return x.LoginName.ToString()
End Function
前端
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="select Count(ID)nums from revs where Email='[email protected]' and Source='PUB' and Status='a'"></asp:SqlDataSource>
我试图把<%= getEmail()%>而不是电子邮件,但没有运气
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="select Count(ID)nums from revs where Email='<% =getEmail() %>' and Source='PUB' and Status='a'"></asp:SqlDataSource>
容易,但冗长,所以我链接MSDN文章:https://msdn.microsoft.com/en-us/library/z72eefad%28v=vs.140%29.aspx? F = 255&MSPPError = -2147217396。简而言之,使用SQL参数并在页面加载时填充它们。 –
现在即时阅读,但我不知道如何使用我的功能来改变选择参数 – bigdowg
当你说你“没有运气”,发生了什么?空白,错误,蝙蝠飞出屏幕:)? –