Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear , I am developing a web application In which i have users , the user have the following information
User(ID(P),Name,EMail,Password,SecutiryQuestion,SecurityANswer,District,TEhsil,UCS,Villages)

Now All other infromation is simpler one but the district ,tehsil,ucs,villages are cascade in nature mean that one district can have many Tehsil,one tehsil can have many UCS, and one ucs can have many villages they are cascade in nature ,
I have placed checkboxlist item for all of them and created four tables first for district(Districtid(P),DistrictName)
Tehsil(TehsilID(P),TEhsilName,DistrictID(F))
UC(UCID(P),UCNAME,TehsilID(F))
VILAGES(VILLAGEIF(P),VIllageNAme,UCID(F))
and i am populating them based on there checkboxlist value selection Now for saving a single user i have these rules
1-One user must have one or more districts
2-one user can have no or many TEhsils
3-One user can have no or many UCs
4-One user can have no or many Village

For user information I have created a table (userid(P),Name,EMail,Password,SecurityQuestion,SecurityAnswer,DistrictID)

and another details table where i have userid as foreign key
UserDetails(Userid(F),RecordID(P),Districtid(F),(TEHSILID(F),UCID(F),VIllageID(F))


tell me this structure is good for inserting and showing checkbos list on edit as well or not
Posted

1 solution

This seems okay, but i like to point you in a different direction. How about making a single table named Region which will hold the whole hierarchy that is (district, tehsil, UC, Village). For example Region(Region_ID, Parent_Region_ID, RegionName, IsTehsil, IsUC, IsVillage, IsDistrict, etc)

Lets assume you have following structure

Region_Id -> Parent_region_id -> Region_Name
1 ->NULL -> Root
2 ->1 -> Karachi
3 ->2 -> Karachi Tehsil 1
4 ->3 -> Karachi Tehsil 1 UC 1
5 ->4 -> Karachi Tehsil 1 UC 1 Village 1

and this can go on and on. This will help you preserve the structure more naturally and elegantly. For User Table you can modify your user detail table as follow

User_Detail(Record_ID, User_ID, ASSOCIATED_REGION_ID (FK REGION_ID)). For understanding purpose lets say you have a user ACME which is associated with District only.

For this purpose you will assign him as follows
Record_id -> User_Id -> Associated_Region_ID
1 -> 1 (ACME) -> 2 (karachi)

Similarly you can assign this user to village level as well like below
Record_id -> User_Id -> Associated_Region_ID
1 -> 1 (ACME) -> 5 (Village 1)

Since the hierarchy is preserved you can easily assign the hierarchy to any user.

Hopes this help you make a good design
 
Share this answer
 
Comments
Malikdanish 2-Feb-15 2:50am    
Dear I Got What you have assist me , The problem is that i am new to programming and Development IF I made a singel table to manage the regions then how i Associate each user to the combination of these four entities mean (district,TEhsil,UC,Villages) For example Consider the following case
I have one district ,3 Tehsils,90 UCs,200 Villages and there not certain rules of association mean that a user can be assigned one district , 3 tehsil,4 ucs,and then the associated villages(any number of these villages) .

Now i am saving the records but the problem comes in editing on edit i have 200 rows and the datareader goes row by row for example if first IT first loop through the District and then pass this district id to Tehsil Method and populates tehsils and then find the selcted tehsil and pass this tehsil to UC method and then find the selected uc and pass this uc id to villages method to pupulates and then select the selected villages so if i have 200 Rowss commming then while loop iterate 200 times so i think it times out on edit and make the process slow , do u have any example for reference then share please

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