前面代码中的SQL select语句 [英] SQL select statement in code in front
问题描述
我在代码前面有一个select语句如下:
Hi,
I have a select statement in code infront as following:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:VSGIHURConnectionString %>"
SelectCommand="SELECT distinct size,UniformID FROM [uniforminfo] where UniformName=''+lbl_uniformid+'' and status= ''a'' ORDER BY UniformID">
</asp:SqlDataSource>
UniformName基于网格中lbl_uniformid的选择。问题是我如何根据用户选择的uniformid重写上面的sql语句where UniformName =''+ lbl_uniformid +''(意味着当用户在网格中选择uniformid时,select语句将根据用户选择正确的大小用户选择统一)?
这是网格中UniformName的代码
the UniformName is based on the selection of lbl_uniformid in the grid. The question is how can i rewrite the above sql statement "where UniformName=''+lbl_uniformid+''" based on the user selected uniformid (means when user choose a uniformid in the grid then the select statement will select a correct size based on the user chosen uniformid)?
Here is the code of UniformName in the grid
<asp:TemplateField HeaderText="Type Of Uniform" Visible="true" ItemStyle-Width="200" >
<ItemTemplate>
<asp:Label ID="lbl_uniformid" runat="server" Text='<%#Eval("uniformgroupname") %>'
Visible="true"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddl_uniformgroupname" runat="server" AutoPostBack="true" runat="server"
BackColor="White" CompletionListCssClass="completeListStyle"
Text='<%# Eval("uniformgroupname") %>' ontextchanged="txt_ddl_uniformgroupname"
style="font-family: 'Century Gothic';" Visible="true"
>
</asp:TextBox>
<asp:AutoCompleteExtender ID="ddl_uniformgroupname_AutoCompleteExtender" runat="server" CompletionInterval="100"
CompletionListCssClass="completeListStyle" DelimiterCharacters="" Enabled="True"
MinimumPrefixLength="0" ServiceMethod="GetCompletion_ddl_uniformgroupname" ServicePath=""
TargetControlID="ddl_uniformgroupname">
</asp:AutoCompleteExtender>
</EditItemTemplate>
</asp:TemplateField>
感谢任何想要帮助我解决问题的人。
非常感谢& H @ ppy 2013.
sp
Appreciate to anyone who want to assist my problem.
Thanks a lot & H@ppy 2013.
sp
推荐答案
ConnectionStrings:VSGIHURConnectionString%>
SelectCommand =SELECT distinct size,UniformID FROM [uniforminfo],其中UniformName =''+ lbl_uniformid +''和status =''a''ORDER BY UniformID>
< / asp:SqlDataSource>
ConnectionStrings:VSGIHURConnectionString %>" SelectCommand="SELECT distinct size,UniformID FROM [uniforminfo] where UniformName=''+lbl_uniformid+'' and status= ''a'' ORDER BY UniformID"> </asp:SqlDataSource>
UniformName基于网格中lbl_uniformid的选择。问题是如何重写上面的sql语句where UniformName =''+ lbl_uniformid +''基于用户选择的uniformid(意味着当用户在网格中选择uniformid时,select语句将根据用户选择的uniformid选择正确的大小)?
这是网格中UniformName的代码
the UniformName is based on the selection of lbl_uniformid in the grid. The question is how can i rewrite the above sql statement "where UniformName=''+lbl_uniformid+''" based on the user selected uniformid (means when user choose a uniformid in the grid then the select statement will select a correct size based on the user chosen uniformid)?
Here is the code of UniformName in the grid
<asp:TemplateField HeaderText="Type Of Uniform" Visible="true" ItemStyle-Width="200" >
<ItemTemplate>
<asp:Label ID="lbl_uniformid" runat="server" Text='<%#Eval("uniformgroupname") %>'
Visible="true"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddl_uniformgroupname" runat="server" AutoPostBack="true" runat="server"
BackColor="White" CompletionListCssClass="completeListStyle"
Text='<%# Eval("uniformgroupname") %>' ontextchanged="txt_ddl_uniformgroupname"
style="font-family: 'Century Gothic';" Visible="true"
>
</asp:TextBox>
<asp:AutoCompleteExtender ID="ddl_uniformgroupname_AutoCompleteExtender" runat="server" CompletionInterval="100"
CompletionListCssClass="completeListStyle" DelimiterCharacters="" Enabled="True"
MinimumPrefixLength="0" ServiceMethod="GetCompletion_ddl_uniformgroupname" ServicePath=""
TargetControlID="ddl_uniformgroupname">
</asp:AutoCompleteExtender>
</EditItemTemplate>
</asp:TemplateField>
感谢任何想要帮我解决问题的人。
非常感谢& H @ ppy 2013.
sp
Appreciate to anyone who want to assist my problem.
Thanks a lot & H@ppy 2013.
sp
你这样做的方式是完全错误的。您需要在SqlDataSource控件中使用参数。看来你需要做很多练习。只需访问以下链接:
使用参数SqlDataSource控件 [ ^ ]
使用SqlParameter表示存储过程返回值和输出参数 [ ^ ]
SqlParameter示例,如何在ASP.Net中使用SqlParame#C#,SqlParameter,SqlDataReader,SqlCommand,SqlConnection示例 [ ^ ]
--Amit
The way you are doing this, is totally wrong. You need to use Parameters in SqlDataSource Control. It seems you need to do a lots of practice on it. Just visit the below links:
Using Parameters with the SqlDataSource Control[^]
Use a SqlParameter to represent stored procedure return values and output parameters[^]
SqlParameter Example, How to use SqlParameter in ASP.Net C#, SqlParameter, SqlDataReader, SqlCommand, SqlConnection Example[^]
--Amit
这篇关于前面代码中的SQL select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!