Passing values to sql datasource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Passing values to sql datasource

    Hi

    I am trying to pass the asp.net membership username to the sqldatasource of
    a gridview as below;

    <asp:SqlDataSou rce ID="EventsSqlDa taSource" runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:MyConnStr %>" SelectCommand=" SELECT
    * FROM [MyTable] WHERE [Username] =
    '<%Me.User.Iden tity.Name%>'"></asp:SqlDataSour ce>

    It is not working. How can I do it correctly?

    Thanks

    Regards


  • Munna

    #2
    Re: Passing values to sql datasource

    On Jun 1, 9:42 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
    Hi
    >
    I am trying to pass the asp.net membership username to the sqldatasource of
    a gridview as below;
    >
    <asp:SqlDataSou rce ID="EventsSqlDa taSource" runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:MyConnStr %>" SelectCommand=" SELECT
    * FROM [MyTable] WHERE [Username] =
    '<%Me.User.Iden tity.Name%>'"></asp:SqlDataSour ce>
    >
    It is not working. How can I do it correctly?
    >
    Thanks
    >
    Regards
    Hi i have tried your same code and worked okay make be you are meesing
    some thing....

    here is the code i tried..

    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConnectionStrin g="<%$Connectio nStrings:Connec tionString %>"
    SelectCommand=" SELECT * FROM [testtable] where id = '<%
    Page.User.Ident ity.Name %>' "></asp:SqlDataSour ce>

    Best of luck

    Munna



    Comment

    • Munna

      #3
      Re: Passing values to sql datasource

      Hi its me again...

      I found another way to make things work i have tested it and works
      pretty fine..
      in markup i actually didn't put any select command.

      instead i left the select command blank

      i assigned the select command in code behind file in page load
      event ...

      SqlDataSource1. SelectCommand = "SELECT * FROM [testtable] where id
      like '%" + Page.User.Ident ity.Name + "%'";

      and

      data source mark up is

      <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      ConnectionStrin g="<%$Connectio nStrings:Connec tionString %>" ></
      asp:SqlDataSour ce>


      Best of luck

      Munna



      Comment

      Working...