ASP:SqlDataSource的为DataSet项目项目、ASP、SqlDataSource、DataSet

2023-09-04 03:16:45 作者:反杀

我有一个asp:SqlDataSource的ID =SqlDataSource1工具,在我的aspx页面,我想要做在C#锐利code的背后,是转移的数据源返回的记录,并把它们放到一个数据集,所以我可以添加分页到我的网页,我怎么做,我尝试到目前为止都失败了?!

我的努力,到目前为止已大致为:

数据集产品=新的DataSet(); 项目= SqlDataSource1.Data();

但我得到的错误是,SqlDataSource1控制是不是在这样的背景下访问,所以很明显的智能感知不捡起来,所以数据()位在我的部分...

感谢,R

解决方案

flavour404,你不应该得到这个错误,如果你设置了控制得当。我只是测试你的情况和它的作品出你刚才提到的错误。

SqlDataSource1没有任何数据的方法,你可能会寻找选择()方法,它不返回数据集。如果设置SqlDataSource.DataSourceMode属性设置为数据集,你会得到DataView对象。请参阅下面

样本

 < ASP:SqlDataSource的ID =SqlDataSource1=服务器DataSourceMode =数据集
            的ConnectionString =&其中;%$的ConnectionStrings:testConnectionString%>中
            的SelectCommand =SELECT * FROM [阅读]>< / ASP:SqlDataSource的>

数据视图testView =(数据视图)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
 

MSDN阅读详细内容:

http://msdn.microsoft.com/en-us/library/ dz12d98w.aspx http://msdn.microsoft.com/en-us/library /system.data.dataview.aspx

希望这有助于!

Asp.net中VS2010中为SQLDataSource控件配置数据源,为什么到这一步进行不下去了 求大神解答

I have an asp:SqlDataSource ID="SqlDataSource1" tool on my aspx page, what I want to do in the c# sharp code behind is transfer the records returned by the datasource and put them into a DataSet, so that I can add paging to my page, how do I do that, my attempts so far have failed?!

My attempts so far have been along the lines of:

DataSet Items = new DataSet(); Items = SqlDataSource1.Data();

But the error I am getting is that the SqlDataSource1 control is not accessible in this context and so obviously the intellisense is not picking it up, so the 'Data()' bit is complete fiction on my part...

Thanks, R

解决方案

flavour404, You should not get that error if you have set up the control properly. I just tested your scenario and it works with out the error you have mentioned.

SqlDataSource1 does not have any Data method, you might be looking for Select() method and it does not return DataSet. If you set SqlDataSource.DataSourceMode property to 'DataSet' you would get DataView object. See the sample below

<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"
            ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
            SelectCommand="SELECT * FROM [Readings]"></asp:SqlDataSource>

DataView testView = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

Read MSDN for details:

http://msdn.microsoft.com/en-us/library/dz12d98w.aspx http://msdn.microsoft.com/en-us/library/system.data.dataview.aspx

Hope this helps!