first table (users)
Users(userid(P),UserName,Email,Password,DistrictID)
UserAndDistricts(DistrictID(P),DistrictName,UserID(F))
UserAndTehsils(TehsilID(P),TEhsilName,UserID(F))
UserAndUcs(UCID(P),UCName,UserID(F))
UserAndVillage(VillageID(P),VillageName,UserID(F))
I have 12 user into the user table
i have one record in district table mean all user belong to one district
I have three records in tehsil table I have three tehsil and all user belong to that
I have 25 rows in ucs table
I have 83 Rows in village table
all table are saving the user id as well as foreign key but when i am using the below query it gives me 4150 rows why duplicating so much data
SELECT U.UserId,U.[Address],U.City,u.Country,UT.TehsilId,UC.UCID ,UC.UCName,UV.VillageId ,UV.VillageName ,UT.TehsilName,U.DistrictId,UD.DistrictName ,UD.DistrictId ,UD.UserId,U.FullName,U.IPAddress,U.IsActive,U.IsAdmin,U.IsPasswordReset,U.IsReportable,U.IsVisible,U.CreateDate ,U.Mobile,U.Password,U.ReporintPerson,U.SecurityAnswer,U.SecurityQuestion ,U.UserId,U.Email,U.UserTypes FROM Users U
RIGHT JOIN UserDistricts UD ON UD.UserId=U.UserId
LEFT OUTER JOIN UserTehsils UT ON UT.UserID=U.UserId
LEFT OUTER JOIN UserUcs UC ON UC.UserID=U.UserId
LEFT JOIN UserVillages UV ON UV.UserId=U.UserId
WHERE U.UserId =21

Manish Kumar ChoudharyPosted Jan 22, 2015, 5:28 AM
User table should link to Districts and Districts table should link on tahil and so on tashil should link to village.
Design your structure linke this.
Danish HabibPosted Jan 26, 2015, 3:10 AM
DistrictUsers(DistrictID(P),DistrictName)
TehsilUsers(TehsilID(P),TehsilName,DistrictID(F))
UCSUSERS(UCID(P),UCNAME,TehsilID(F))
VILLAGESUSER(VillageID(P),VillageName,UCID(F))
And I have one record in DistrictUser
three records in TehsilUSers
23 Reoords in UCSUSERS
53 Records in VillagesUsers
on Gridview editing below is my code
it return 3657 Rows Tell me please the mistake
Manish Kumar ChoudharyPosted Jan 22, 2015, 11:58 PM
I don't think it will show down the process of your web application. This is how One To Many relationship work.
You can find the associated District by using
Select Id,DistrictName from tblDistrict where TashilId=
And display it to check box list.
Danish HabibPosted Jan 22, 2015, 11:49 PM
and i have to option to select multiple items so i used checkboxlist
and when i select select the tehsil how I find the associated district of that weather on district checkboxlist i have selected three items so which one associates to that tehsil , I have already a tables for maintaining hierarchy for that cascade then i have to give this tehsil id to dis districts table and find the associated district from there they may slow down the process of my web application
Manish Kumar ChoudharyPosted Jan 22, 2015, 11:25 PM
In tashil entry form add one dropdown for District. The text field for that will be district and value filed of selected district will be Id of that District and save it. Just add that extra field there
Danish HabibPosted Jan 22, 2015, 11:10 PM
TehsilId(P),TehsilName,DistrictID(F) (comming from District table)
I have a question Now how to save the district id while saving the tehsil how to get the actual district id from which that tehsil belongs to
Danish HabibPosted Jan 22, 2015, 5:32 AM
Danish HabibPosted Jan 22, 2015, 5:22 AM
District->tehsils->Ucs-Villages
u mean in last village table i have the above three forign keys as well
like villageID Villagename,UCsID,Tahsilid,District id
Manish Kumar ChoudharyPosted Jan 22, 2015, 5:07 AM
Your table doesn't have proper relation among UserDistricts , UserTehsils and UserVillages so you are not getting proper result.
Alter that first.
Danish HabibPosted Jan 22, 2015, 5:07 AM
Manish Kumar ChoudharyPosted Jan 22, 2015, 5:00 AM
Danish HabibPosted Jan 22, 2015, 4:52 AM
UserAndVillages table:
Manish Kumar ChoudharyPosted Jan 22, 2015, 4:41 AM
Show your table scripts then I may solve it.
Danish HabibPosted Jan 22, 2015, 4:20 AM
yashasvi KumarPosted Jan 22, 2015, 4:07 AM
Please Mark Ans if helpful
Manish Kumar ChoudharyPosted Jan 22, 2015, 3:57 AM
Danish HabibPosted Jan 22, 2015, 3:54 AM
For District tehsil uc and villages i have used the checkboxlist item and they are all populated based on their selection means they are cascade in nature (if you select the district then the associated Tehsils would be populated and if you select the tehsil the associated ucs would be populated and if you select the tehsil the associated ucs would be populated and on selction of the Ucs the associated villages would be populated .
they are good at population side Now i want to store the records for basic information of the user i have created a user table as i mentioned previouslly and for District tehsil ucs and villages i created separate table for all these four and passing the user id as foreign key Now they are saving correct but while retriveing the record in gridview edit mode when I fetching the record it gives me records in 4000 weather i jsut have one district associated with that user
2 tehsil associated with that user
24 ucs associated with that user
83 vilalges associated with that user
below is the query which i want to execuate but it gives me not correct result set
I have used right left inner join all but not solved
yashasvi KumarPosted Jan 22, 2015, 3:42 AM
Danish HabibPosted Jan 22, 2015, 3:30 AM
yashasvi KumarPosted Jan 22, 2015, 3:26 AM