I'm trying to pass User.Identity.Name to a sqldatasource where query in vb asp and as always getting in to a pickle.
On page load I have the following to set up the parameter.
in this instance; I'm stripping out the domain as I just want to pass the userid. I'm now having a brainburp in passing that to the sqldatasource.
I suspect the code bahind isn't feeding to SelectParamters in the way I expect but I've tried various means and way and syntax's and not getting very far!
Any pointers would be greatly appreciated!
TIA!
On page load I have the following to set up the parameter.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' When your page opens, set your datasource parameter '
' SqlDataSource1.SelectParameters.Add("@UserName", User.Identity.Name)
SqlDataSource1.SelectParameters.Add("@UserName", HttpContext.Current.User.Identity.Name.Substring(HttpContext.Current.User.Identity.Name.IndexOf("\") + 1))
Message.Text &= "User NameNoDomain: " & HttpContext.Current.User.Identity.Name.Substring(HttpContext.Current.User.Identity.Name.IndexOf("\") + 1)
End Sub
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:blahblah %>" SelectCommand="SELECT blah FROM blahland WHERE (userblah LIKE '%' + @UserName + '%')">
<SelectParameters>
<asp:Parameter DefaultValue="@UserName" Name="Username" />
</SelectParameters>
</asp:SqlDataSource>
Any pointers would be greatly appreciated!
TIA!