TableAdapter 仅返回选定的列? (VS2008)
(VS2008)我试图在类型化数据集中配置 TableAdapter 以仅返回其所基于的表的主模式中的某个列子集,但它总是返回带有空白值的整个模式(所有列)在我省略的列中。
TableAdpater 具有来自向导的默认 Fill 和 GetData() 方法,其中包含表中的每一列,这很好。 然后,我添加了一个名为 GetActiveJobsByCustNo(CustNo) 的新参数化查询方法,并且我只在 SQL 查询中包含了我实际上希望出现在该表视图中的几列。
但是,它再次返回主表模式中的所有列,其中我省略的列为空值。
我想要这个的原因是,我可以只获取几列,以便在 ASP.NET GridView 中通过 AutoGenerateColumns 使用该表视图。 通过它返回架构中的每一列,我的演示文稿 GridView 包含了更多我想向用户显示的列。 而且,我想避免必须在 GridView 中声明列。
(VS2008) I'm trying to configure a TableAdapter in a Typed DataSet to return only a certain subset of columns from the main schema of the table on which it is based, but it always returns the entire schema (all columns) with blank values in the columns I have omitted.
The TableAdpater has the default Fill and GetData() methods that come from the wizard, which contain every column in the table, which is fine. I then added a new parameterized query method called GetActiveJobsByCustNo(CustNo), and I only included a few columns in the SQL query that I actually want to be in this table view.
But, again, it returns all the columns in the master table schema, with empty values for the columns I omitted.
The reason I am wanting this, is so I can just get a few columns back to use that table view with AutoGenerateColumns in an ASP.NET GridView. With it giving me back EVERY column i nthe schema, my presentation GridView contains way more columns that I want to show th user. And, I want to avoid have to declare the columns in the GridView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您向给定的 TableAdapter 添加新查询时,它将采用它所附加到的架构,这就是为什么您会获得不需要的列的空白值。
由于您提到已经创建了该过程,因此您需要做的就是使用服务器资源管理器连接到数据库,然后将该存储过程拖到您的 XSD 工作区中。 这样做的目的是创建一个单独的 QueryAdapter,其中仅包含您指定的列(仍然是强类型),并且您可以使用该 QueryAdapter 与 GridView 绑定/交互。
When you add a new query to a given TableAdapter, it is going to assume the schema in which it is attached to, which is why you are getting blank values for the columns you don't want.
Since you mentioned having already created the procedure, what you need to do is use the Server Explorer to connect to the database and simply drag that stored procedure over into your XSD work area. What this will do is create a separate QueryAdapter that will have just the columns you specified (still strongly typed) and you can bind/interact with your GridView using that QueryAdapter instead.
强类型数据集是否在另一个返回表中所有行的查询中使用?
您可以做的是使用强类型数据集创建数据视图,并为 DataGridView 公开数据表。
我不确定您的要求是什么,但这个例子应该对您有帮助:
Is the strongly typed dataset used in another query that returns all the rows from the table?
What you could do is create a dataview using the strongly typed dataset and expose a data table for your DataGridView.
I'm not sure what your requirements are totally, but this example should help you:
只需在绑定到 Gridview 之前删除运行时不需要的列即可。 毕竟底层类仍然只是一个 DataTable。
Just delete the columns you don't want at run-time before you bind to your Gridview. The underlying class is still just a DataTable after all.