如何使用TableName的Textbox输入将Table调用到Datagridview? [英] How do I call Table into Datagridview Using Textbox input for TableName?
问题描述
嗨专家。
我的My Access数据库中有多个表,护照编号为表名。并且所有表都有相同的列。
现在我的问题是如何将特定的表调用到DataGridview中。
示例:我已经采取1个TextBox,1个按钮和1个DataGridview。
当我在TextBox中输入护照编号并单击按钮时,DataGridView将使用特定Passport No's Table进行更新()。
请给出建议或任何参考以获得解决方案。
在此先感谢..
我是Dotnet新手。请不要误会我的问题。
至少我没有得到如何启动代码。
Hi Experts.
I have Mutliple Tables in My Access Database with passport No. as Table Names. And All Tables have same Columns.
Now My Question is How could i call particular table into DataGridview.
Example : I have taken 1 TextBox, 1 Button, And 1 DataGridview.
When I Enter Passport No. in TextBox and Clicking on Button, The DataGridView is to be updated with particular Passport No's Table().
Please give suggestion or any reference to get solution.
Thanks in Advance..
I am New to Dotnet. Please dont Missunderstand for my question.
At least i am not getting how start code it.
推荐答案
首先你最好改变你的桌面设计为所有护照No / Type的单桌。
例如:
first of all you better change your table design to having single table for all the passport No/Type.
example :
TableforType1
Col1 col2
val11 val12
TableforType2
Col1 col2
va21 val22
可以更改为MyTable
can be change to MyTable
TypeID Col1 col2
1 val11 val12
2 val21 val22
3 val31 val32
1 val12 val13
TypeTable
ID TypeName
1 Type A
2 Type B
3 New Type
通过使用上面两个表,您可以处理多种类型,而无需为每种新类型创建新表。
当您需要检索类型1的数据时例如;
by using above two tables you can handle many types without creating new tables for each new type.
when you need to retrieve data for type 1 for example ;
select m.Col1, m.col2 from MyTable m join TypeTable t on m.TypeId = t.ID where t.TypeName ='Type A'
所以你没有需要构建运行时sql语句或在决定选择哪个数据库表时创建复杂的逻辑。
so you don't need build runtime sql statements or creating complex logic on deciding which database table to select.
这篇关于如何使用TableName的Textbox输入将Table调用到Datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!