passing variable to sql statement in asp.net 2.0?

Discussion in 'ASP .Net Web Controls' started by billb, Jul 10, 2006.

  1. billb

    billb Guest

    Anyone have any ideas how this works? I've tried old school and a ton of
    other things with no success. Any help would be greatly appreciated. Thanks.



    <body>

    <form id="form1" runat="server">

    <%

    '' get user login info and strip domain name....

    Dim X As Object, strCompletePath As String, getUser As String

    strCompletePath = Request.ServerVariables("LOGON_USER")

    X = Split(strCompletePath, "\")

    getUser = X(UBound(X))

    strFileName.Text = getUser

    %>

    <asp:TextBox ID="strFileName" runat="server" MaxLength="1000"></asp:TextBox>

    <br />

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataKeyNames="Alias"

    DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to
    display." CellPadding="4" ForeColor="#333333" GridLines="None">

    <Columns>

    <asp:BoundField DataField="Alias" HeaderText="Alias" ReadOnly="True"
    SortExpression="Alias" />

    <asp:BoundField DataField="FirstName" HeaderText="FirstName"
    SortExpression="FirstName" />

    <asp:BoundField DataField="LastName" HeaderText="LastName"
    SortExpression="LastName" />

    <asp:BoundField DataField="Active" HeaderText="Active"
    SortExpression="Active" />

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <EditRowStyle BackColor="#999999" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
    />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
    />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"

    ConnectionString="<%$ ConnectionStrings:USTools_DevConnectionString1 %>"

    ProviderName="<%$
    ConnectionStrings:USTools_DevConnectionString1.ProviderName %>"

    SelectCommand="SELECT * FROM [User] WHERE [Alias] LIKE '<%=getUser%>' "
    OldValuesParameterFormatString="">

    <%-- <InsertParameters>

    <asp:ControlParameter

    ControlID="strFileName"

    DefaultValue="0"

    Name="getUser"

    PropertyName="Text"

    Direction="Input"

    ConvertEmptyStringToNull="true"

    Size="1000"

    />

    </InsertParameters>--%>

    </asp:SqlDataSource>

    </form>

    </body>
    billb, Jul 10, 2006
    #1
    1. Advertising

  2. hi, since you are already using a ControlParameter, pass that instead of
    trying to use inline code blocks inside your SelectCommand. So instead of
    <%=getUser%> supply instead just @getUser.

    Readup more on the ControlParameter here :
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx

    Regards,
    Alessandro Zifiglio
    http://www.AsyncUI.net

    "billb" <> ha scritto nel messaggio
    news:...
    > Anyone have any ideas how this works? I've tried old school and a ton of
    > other things with no success. Any help would be greatly appreciated.
    > Thanks.
    >
    >
    >
    > <body>
    >
    > <form id="form1" runat="server">
    >
    > <%
    >
    > '' get user login info and strip domain name....
    >
    > Dim X As Object, strCompletePath As String, getUser As String
    >
    > strCompletePath = Request.ServerVariables("LOGON_USER")
    >
    > X = Split(strCompletePath, "\")
    >
    > getUser = X(UBound(X))
    >
    > strFileName.Text = getUser
    >
    > %>
    >
    > <asp:TextBox ID="strFileName" runat="server"
    > MaxLength="1000"></asp:TextBox>
    >
    > <br />
    >
    > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    > DataKeyNames="Alias"
    >
    > DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to
    > display." CellPadding="4" ForeColor="#333333" GridLines="None">
    >
    > <Columns>
    >
    > <asp:BoundField DataField="Alias" HeaderText="Alias" ReadOnly="True"
    > SortExpression="Alias" />
    >
    > <asp:BoundField DataField="FirstName" HeaderText="FirstName"
    > SortExpression="FirstName" />
    >
    > <asp:BoundField DataField="LastName" HeaderText="LastName"
    > SortExpression="LastName" />
    >
    > <asp:BoundField DataField="Active" HeaderText="Active"
    > SortExpression="Active" />
    >
    > </Columns>
    >
    > <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    >
    > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    >
    > <EditRowStyle BackColor="#999999" />
    >
    > <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
    > />
    >
    > <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
    > />
    >
    > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    >
    > <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    >
    > </asp:GridView>
    >
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    >
    > ConnectionString="<%$ ConnectionStrings:USTools_DevConnectionString1 %>"
    >
    > ProviderName="<%$
    > ConnectionStrings:USTools_DevConnectionString1.ProviderName %>"
    >
    > SelectCommand="SELECT * FROM [User] WHERE [Alias] LIKE '<%=getUser%>' "
    > OldValuesParameterFormatString="">
    >
    > <%-- <InsertParameters>
    >
    > <asp:ControlParameter
    >
    > ControlID="strFileName"
    >
    > DefaultValue="0"
    >
    > Name="getUser"
    >
    > PropertyName="Text"
    >
    > Direction="Input"
    >
    > ConvertEmptyStringToNull="true"
    >
    > Size="1000"
    >
    > />
    >
    > </InsertParameters>--%>
    >
    > </asp:SqlDataSource>
    >
    > </form>
    >
    > </body>
    >
    >
    Alessandro Zifiglio, Jul 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Froefel
    Replies:
    1
    Views:
    770
    Mark Rae [MVP]
    Jul 4, 2007
  2. Julia Jacobson
    Replies:
    2
    Views:
    1,018
    Gregory Ewing
    Aug 30, 2010
  3. weiwei

    asp and sql statement in sql server db

    weiwei, Sep 22, 2004, in forum: ASP General
    Replies:
    3
    Views:
    190
    Jeff Cochran
    Sep 22, 2004
  4. Tim
    Replies:
    3
    Views:
    228
  5. Replies:
    1
    Views:
    108
    Mike Brind
    Apr 25, 2006
Loading...

Share This Page