限制使用 TableAdapter(类型化数据集)返回的行数
有谁知道使用类型化 TableAdapter 时限制返回行数的最佳方法?选项似乎是:
- 将“top X”作为参数传递(直到我们使用 SQLS2008 才能执行此操作
- 发出动态 SQL 语句:
set rowcount X
在调用我的 tableadapter 方法之前,然后set rowcount 0
之后 - 。
非常感谢。
Does anyone know the best way to limit the number of rows returned when using typed TableAdapters? Options appear to be:
- Pass "top X" as a parameter (can't do this until we're on SQLS2008
- Issue a dynamic SQL statement:
set rowcount X
before calling my tableadapter method, thenset rowcount 0
aftwards. - Something else I haven't thought of :).
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这对我来说效果很好。
该参数与 TableAdapter 中的任何其他参数一起生成。
This works fine for me.
The parameter is generated along with any others in the TableAdapter.
我使用参数化存储过程来实现这一点。
I achieve this using parameterized stored procedure.
我找到了更好的方法。
您无法参数化“TOP”值,但可以参数化“SET ROWCOUNT X”值。
因此,这是有效的:
但是我确实需要处理发生的异常,这将阻止
set rowcount 0
语句运行。我会继续挖掘。更新
我的老板告诉我如何让它发挥作用(而且它太简单了,我有点尴尬),但我会让他发布他的答案,而不是让它看起来像是我自己找到的。 :)
I have found a better way.
You can't parameterise the "TOP" value, but you can parameterise the "SET ROWCOUNT X" value.
Therefore, this works:
However I do need to deal with exceptions happening, which would prevent the
set rowcount 0
statement from running. I'll keep digging.UPDATE
My boss told me the way to make it work (and it's so simple I'm a bit embarrassed) but I'm going to get him to post his answer rather than make it look like I found it myself. :)
TableadApter 使用 SqlDataAdapter,它已经具有此功能。
操作:
单击 Fill() 或 FillByXXX() 方法
,然后按 F12 - 它会将您带到其源代码 由设计师生成。
复制此方法。
转到数据集设计器,单击表适配器并按F7 - 它将为TableAdapters命名空间创建/打开代码。
在这里粘贴 Fill() 方法并修改它,如下例所示:
然后您可以使用它:
TableadApter use SqlDataAdapter, which already has this feature.
What to do:
Click on Fill() or FillByXXX() method
and press F12 - it will bring you to its source code generated by designer.
Copy this method.
Go to the DataSet designer, click on table adapter and press F7 - it will create/open code for the TableAdapters namespace.
Paste Fill() method here and modify it some like in example below:
and then you can use it as:
您可以使用 TOP n,但必须将其放在括号中,如下所示:
您还可以按如下方式对其进行参数化:
You can use TOP n, but you have to put brackets around it like so:
You can also parameterise it as follows: