Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 20-Mar-16 21:24pm
v2

1 solution

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      ...

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.
 
Share this answer
 
v2
Comments
koolprasad2003 21-Mar-16 3:04am    
Good way to implement +5
Afzaal Ahmad Zeeshan 21-Mar-16 4:24am    
5ed; I will add the normalization to your post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900