我怎样才能保存身份,国籍,宗教专栏 [英] How can I save id , nationality, religion columns

查看:84
本文介绍了我怎样才能保存身份,国籍,宗教专栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3列:Id,国籍,宗教

当我保存国籍身份证件

例如:

1,American

2,Jordanian

然后我保存的宗教必须变成这样的

1,Christian ...



我尝试了什么:



当我点击按钮时,我将在网格视图中显示一个新行。 。

但是国籍的id与宗教不同,例如:
例如:

i存储id = 1,国籍=jordanian

id = 2,国籍=美国人

然后我想存储宗教信仰,id将成为(1)不是(3)

gridview必须显示如下:

id,nationality,religion

______________________________

1,jordanian

______________________________

2,美国

______________________________

1 ,, Christian

_______________________________

...我希望如此你明白我的意思

i have 3 columns : Id , nationality, religion
when i save the id for nationality
example :
1, American
2, Jordanian
then i saved religion must become like this
1,Christian...

What I have tried:

when i click the button new i will appear a new row in grid view ..
but the id for nationality differ from the religion ,
for example :
i stored id =1, nationality="jordanian"
id=2, nationality=" American"
then i wanna to store religion , the id will become (1) not (3)
the gridview must display like this :
id , nationality, religion
______________________________
1 ,jordanian
______________________________
2 ,American
______________________________
1 , ,Christian
_______________________________
...I hope that you understand what I mean

推荐答案

不要将id混合在一个列中 - 如果你这样做,那么很难(如果不是不可能的话)从id引用的行。

相反,有一个nationalityId和一个ReligId并将它们分开(如果你使用的是DB,那么这些就是单独的表格:

Nationalities

Don't mix id's in a single column - if you do, then it gets difficult (if not impossible) to work out from the row what the id refers to.
Instead, have a nationalityId and a religionId and keep them separate (If you were using a DB, then these would be separate tables:
Nationalities
Id     Name
1      American
2      Jordanian



宗教


Religions

Id     Name
1      Christian
2      Jedi
3      Pastafarian



然后你有第三张桌子(你是用于提供链接:

用户


You then have a third table (which you use to provide the links:
Users

Id     Nationality   Religion  Name
1      1             1         Joe
2      1             2         Luke
3      2             1         Amir
4      ...



这是因为你需要规范化数据库 [ ^ ],以便以后可以有效地获取和更新数据。



如果您使用VB中的类来表示这一点,那么您将创建三个类,并使用第三个类中的引用将您链接到国籍和宗教的实际数据实例。如果您在国籍和宗教类中覆盖ToString,DGV将自动为您显示正确的数据。


This is because you need to normalize the databases[^], so that later you can fetch and update the data efficiently.

If you are using classes in VB to represent this, then you would create three classes, and use references in the third to link you to the actual data instances for Nationality and Religion. If you override ToString in the Nationality and Religion classes, the DGV will display the right data for you automatically.


这篇关于我怎样才能保存身份,国籍,宗教专栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆