开发者

Declaring a Variable TableAdapter on a Form

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜