Quiero hacer una consulta a un servidor SQL que en la cláusula WHERE incluya una variable de ASPX, en este caso el nombre de usuario logueado.
Adjunto el código:
SOPORTE.ASPX
Código:
SOPORTE.ASPX.VB<div class="gensoporte"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:trackpasoConnectionString %>" SelectCommand="SELECT DISTINCT W.WORKITEMKEY, S.LABEL as ESTADO, W.PACKAGESYNOPSYS FROM TWORKITEM as W, TSTATE as S, TCLIENTE as C WHERE (W.STATE = S.PKEY) AND (W.CLIENTEKEY = C.PKEY) AND (C.LABEL = ' & strUser & ') AND (S.LABEL != 'closed')"></asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1"> </asp:GridView> <asp:Label ID="label11" runat="server" Text="Label"></asp:Label> </div>
Código:
Como podéis ver, la variable que quiero emplear es strUser, que la genero al cargar la página soporte.aspx y toma el valor del usuario logueado. Si muestro la variable en un label lo hace correctamente.Public Class soporte Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strUser As String = System.Web.HttpContext.Current.User.Identity.Name Me.label11.Text = strUser End Sub End Class
Y si sustituyo la variable en la sentencia SQL por el nombre del usuario logueado también me muestra datos.
A ver si me podéis echar una mano, que veo el tema complicado..
Saludos.