在表单上声明变量 TableAdapter

发布于 2024-11-29 19:25:01 字数 396 浏览 2 评论 0原文

希望这是一个相当简单的问题。

我正在我的应用程序中构建通用搜索表单。这将允许用户在整个应用程序中搜索各种记录。

我似乎无法弄清楚的一件事是如何允许 TableAdapter 的声明在运行时更改。应用程序的每个部分都会向搜索表单传递一个变量,以指定应加载哪个表。

在表单类中,我有以下内容:

FRIEND WITHEVENTS tbaSearchData AS database.databaseTableAdapters.TableOneTableAdapter

这对于 TableOne 来说非常有用。但是,我有大约一百个表可以搜索。

为了加载数据,我使用 DataGridView 并通过私有方法填充它。

任何帮助将不胜感激。

This is hopefully a fairly straightforward question.

I am building a generic search form in my application. This will allow the user to search for various records throughout the application.

The one thing I cannot seem to figure out is how to allow the declaration of the TableAdapter to change at run-time. Each part of the app will be passing a variable to the search form to specify which table should be loaded.

In the form class I have the following:

FRIEND WITHEVENTS tbaSearchData AS database.databaseTableAdapters.TableOneTableAdapter

This is great for TableOne. But, I have about a hundred tables that could be searched through.

To load the data I'm using a DataGridView and populating it via a private method.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2024-12-06 19:25:01

Tableadapter 实际上是用于设计时设置的,并且在运行时不容易更改。您可能需要考虑使用 DataAdapter(例如 SqlDataAdapter)来处理这些请求。这些对象的开销较低,并且不像表适配器那样特定于类型,因此在运行时创建它们是一个不错的解决方案。

Tableadapter is really meant for design time setup and doesn't easily change at runtime. You may want to look into using a DataAdapter, like SqlDataAdapter, for these requests. These objects have lower overhead and aren't as type specific as a tableadapter so making them at runtime is a decent solution.

素衣风尘叹 2024-12-06 19:25:01

让我们看看我是否理解了这一点。
我提出了两种可能的解决方案

  1. 从应用程序的各个角度,您可以传递专门的 DataAdapter 本身而不是表名,并将通用 DataAdapter 变量分配到搜索表单中。

  2. 您可以在搜索表单中创建通用 DataAdapter 并更改用于加载数据的 SQL 命令。在下面的代码中,da 将是一个 DataAdapter,table 是传递到搜索表单的表名

da.SelectCommand.CommandText = "Select * from " &表

Let's see if I understood this.
I've come up with two possible solutions

  1. From various point of your app, you could pass the specialized DataAdapter itself instead of a tablename and assign to a generic DataAdapter variable into the search form.

  2. You could create a generic DataAdapter into the search form and change the SQL command used to load the data. In the following code, da will be a DataAdapter and table the tablename passed to the search form

da.SelectCommand.CommandText = "Select * from " & table

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文