在强类型 ADO.NET TableAdapter 中参数化架构
我正在尝试在 ADO.Net 中构建强类型数据集,但在 TableAdapters 的一个方面遇到了一些问题。
我的查询看起来像
SELECT *
FROM testdict.ModuleVariable
WHERE Module = ?
我的问题围绕 testdict 部分。我们使用多种不同的模式来访问数据(因为存在多路复用的 Sybase IQ 实例)。如何参数化此查询的架构部分?
我已经尝试过:
SELECT *
FROM ?.ModuleVariable
WHERE Module = ?
但没有成功。我目前的想法是,我可能必须继承 TableAdapter 并手动参数化架构,但我希望有一个更好的解决方案!
提前致谢
I'm trying to build a strongly-typed dataset in ADO.Net and am having a little trouble with one aspect of the TableAdapters.
My query looks like
SELECT *
FROM testdict.ModuleVariable
WHERE Module = ?
My problem revolves around the testdict part. We use several different schemas to access our data (because of a multiplexed Sybase IQ instance). How can I parameterize the schema portion of this query?
I've tried:
SELECT *
FROM ?.ModuleVariable
WHERE Module = ?
but to no avail. My current mindset is that I may have to inherit the TableAdapter and parameterize the schema manually but I am hoping there is a nicer solution!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但是,有一个解决方案。以下是您可以执行此操作的方法。
1.) 将表拖放到类型化数据集设计器中,这将为该表创建类型化数据表以及用于访问数据库表的表适配器。表适配器了解数据表的架构。
2.) 现在在数据库中创建一个存储过程,它采用两个参数。一个是表的架构 [?.ModuleVariable],另一个是您的where 子句 或者您可能想要作为条件的任何内容。您可以根据需要创建此重载。然后,该存储过程将根据参数构造 sql 查询并在数据库上执行。这将将结果集返回到调用表适配器。
3.) 从设计视图中向表适配器添加一个方法,该方法将从存储过程中获取结果。 确保结果的架构完全符合关联数据表的架构。
4.) 现在,您可以从代码中创建表适配器的实例并调用该方法,该方法又将调用您的存储过程并返回填充有结果的数据表。
玩得开心!
However there's a solution for this.Here's how you can do that.
1.) Drag and drop the table into your typed-dataset designer which will create a typed-data-table for the table and the table-adapter to access database table. table adapter is aware of the schema of the data-table.
2.) Now create a stored-procedure in your database that takes two arguments. one is the schema of the table [?.ModuleVariable] and other would be your where clause or maybe anytihng you may want as criteria. You can create overloads of this as you wish. This stored-procedure will then construct the sql query based on the arguments and execute it on the database. This will return the result-set to calling table-adapter.
3.) From the design-view Add a method to table-adapter which will fetch results from the stored-procedure. Make sure that the schema of results exactly meets the schema of the associated data-table.
4.) Now from the code you can create an instance of the table adapter and call the method which in turn will call your stored-procedure and return you with the data-table filled in with results.
Have fun!
您可以重载表适配器或向表适配器添加新函数,因为它们被定义为分部类。这个新函数将架构名称作为参数。例如,Fill(table As (tableName), schemaName As String)。我的做法如下:
部分类 (tableName)TableAdapter
公共重载函数 Fill( _
表 As (表名), _
schemaName 作为字符串)作为整数
结束函数
结束课程
亲切的问候,
卡洛斯·马伦
You can overload or add a new function to the table adapter, because they are defined as partial classes. This new function would have the schema name as a parameter. For example, Fill(table As (tableName), schemaName As String). Here's how I'd do it:
Partial Class (tableName)TableAdapter
Public Overloads Function Fill( _
table As (tableName), _
schemaName As String) As Integer
End Function
End Class
Kind regards,
Carlos Mallen