Home All Groups Group Topic Archive Search About

passing variable to sql statement in asp.net 2.0?

Author
10 Jul 2006 8:02 PM
billb
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>

Author
12 Jul 2006 9:48 AM
Alessandro Zifiglio
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

Show quoteHide quote
"billb" <bkbez***@aimcomm.com> ha scritto nel messaggio
news:uKl26uFpGHA.4236@TK2MSFTNGP03.phx.gbl...
> 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>
>
>