如何在代码隐藏文件中使用 count 函数返回的值

发布于 2024-12-18 07:29:01 字数 1171 浏览 3 评论 0原文

我知道在 sql 查询中可以使用 count 函数返回受影响的行数。我需要使用 sql select 语句返回的值对隐藏文件的代码做出决定。

<asp:sqldatasource ID="Sqldatasource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:CUSTOMERConnectionString %>" 
    SelectCommand=
        "SELECT COUNT O.siren, O.siret, O.sap_code, CLIENT.display_name, CLIENT.departement, STATUS.status_lib_fr, PERSONNEL.dbo.EMPLOYES.display, CLIENT.client_id 
        FROM ORGANIZATION AS O INNER JOIN CLIENT ON O.client_id = CLIENT.client_id       
        WHERE (O.siren = @value) OR (O.siret = @value) OR (O.sap_code = @value) OR (O.name1 LIKE '%' + @value + '%') OR (O.name2 LIKE '%' + @value + '%') OR (O.name_other LIKE '%' + @value + '%') OR (O.name_short LIKE '%' + @value + '%') OR (O.name_long LIKE '%' + @value + '%')" > 
     <SelectParameters>
        <asp:ControlParameter ControlID="TxtValue" Name="value" PropertyName="Text" 
            Type="String" />
     </SelectParameters>
</asp:sqldatasource>
<asp:TextBox ID="TxtValue" runat="server" Width="164px"/>

因此,如果 select 命令返回的值为零,那么我需要在后面的代码中执行另一组操作。但如何获取这个值呢?或者有没有其他方法来确定 select stmt 是否返回任何值? 谢谢!

i know in sql query one can use count function to return the number of rows affected. I need to make a decision on the code behind file using the value returned by my sql select statement.

<asp:sqldatasource ID="Sqldatasource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:CUSTOMERConnectionString %>" 
    SelectCommand=
        "SELECT COUNT O.siren, O.siret, O.sap_code, CLIENT.display_name, CLIENT.departement, STATUS.status_lib_fr, PERSONNEL.dbo.EMPLOYES.display, CLIENT.client_id 
        FROM ORGANIZATION AS O INNER JOIN CLIENT ON O.client_id = CLIENT.client_id       
        WHERE (O.siren = @value) OR (O.siret = @value) OR (O.sap_code = @value) OR (O.name1 LIKE '%' + @value + '%') OR (O.name2 LIKE '%' + @value + '%') OR (O.name_other LIKE '%' + @value + '%') OR (O.name_short LIKE '%' + @value + '%') OR (O.name_long LIKE '%' + @value + '%')" > 
     <SelectParameters>
        <asp:ControlParameter ControlID="TxtValue" Name="value" PropertyName="Text" 
            Type="String" />
     </SelectParameters>
</asp:sqldatasource>
<asp:TextBox ID="TxtValue" runat="server" Width="164px"/>

and so if the values returned by the select command is zero then i need to perform another set of operation in the code behind. but how do one access this value? or is there any other way to determine if the select stmt returned any value or not?
thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜未央樱花落 2024-12-25 07:29:01

为什么不直接将 SQL 语句放在代码隐藏文件中呢?更好的是,执行 LINQ to SQL 查询,该查询将以 IEnumberable 或类似的形式输出结果,具体取决于您可以以各种方式使用的数据。您可以对其调用 .Count() 以查看查询返回了多少条记录,或者如果您只想测试它是否为空,则可以调用 .Any()。

这会将所有数据保留在 C# 代码中,然后您可以根据需要将其发送到页面。可以在此处找到 Linq to SQL 的备忘单 http://msdn.microsoft。 com/en-us/vstudio/bb688085 可以在这里找到更详细的解释http://msdn.microsoft.com/en-us/library/bb425822.aspx。

最近,我必须在我的一个项目中实现 Linq to XML,因为我只有 SQL 经验,并且它的多功能性和易用性给我留下了深刻的印象。绝对值得一看。

Why not put the SQL statement directly in your code-behind file? And better yet, perform a LINQ to SQL query which will spit out a result in the form of IEnumberable<string> or something similar dependent on your data that you can play with in all kinds of ways. You can call .Count() on it to see how many records the query returned, or if you just want to test if it is empty, .Any().

This keeps all the data in the C# code behind which you can then send to the page if need be. A sort of cheat sheet for Linq to SQL can be found here http://msdn.microsoft.com/en-us/vstudio/bb688085 and a more lengthy explanation of it can be found here http://msdn.microsoft.com/en-us/library/bb425822.aspx.

I recently had to implement Linq to XML in a project of mine having only had experience in SQL, and was impressed by its versatility and ease of use. Definitely worth taking a look at.

み格子的夏天 2024-12-25 07:29:01

您可以从 TxtValue.Text 检索值,例如在 OnPreRender 事件处理程序中。

You could retrieve the value from TxtValue.Text, for example in the OnPreRender event handler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文