Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用<;asp:SqlDataSource>;在我的.aspx文件中多次?_Asp.net - Fatal编程技术网

Asp.net 使用<;asp:SqlDataSource>;在我的.aspx文件中多次?

Asp.net 使用<;asp:SqlDataSource>;在我的.aspx文件中多次?,asp.net,Asp.net,我想问一下在asp.net中使用多个SqlDataSource是否可以。抱歉,我的问题是,我刚刚开始编程 <asp:SqlDataSource ID="SqlDataSource9" runat="server" SelectCommand="SELECT cdesc FROM [main] where [cmain]='O' and [cformat]='' order by cdesc" ConnectionString="<%$ ConnectionStr

我想问一下在asp.net中使用多个
SqlDataSource
是否可以。抱歉,我的问题是,我刚刚开始编程

<asp:SqlDataSource ID="SqlDataSource9" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='O' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" /> 

<asp:SqlDataSource ID="SqlDataSource10" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='Q' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" /> 

当然,您可以在单个页面上使用多个SqlDataSource

<asp:SqlDataSource ID="SqlDataSource9" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='O' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" /> 

<asp:SqlDataSource ID="SqlDataSource10" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='Q' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" /> 

但是,如果您想使用到同一个表的连接,而不是使用多个SqlDataSource,您可以将同一SqlDataSource链接到多个源。

为什么不试试看呢?多个相同的源没有任何意义,但是没有理由多个源获取不同的数据会是一个问题。否则,会使页面变得非常不灵活。此外,如果您的查询之间存在如此小的差异,您可以使用参数根据用户输入或您自己的脚本更改变量值(例如,您的
cmain
字段)。你可以很容易地在谷歌上搜索关于它的教程。
<asp:SqlDataSource ID="SqlDataSource9" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='O' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" /> 

<asp:SqlDataSource ID="SqlDataSource10" runat="server" 
     SelectCommand="SELECT cdesc FROM [main] where [cmain]='Q' and [cformat]='' order by cdesc"
     ConnectionString="<%$ ConnectionStrings:My_ConnectionString %>" />