简体   繁体   中英

How to change the column name of datagridview in c#?

In my database i am 5 tables with names 'children' , 'personal' , 'spouse' , 'occup_contact' , 'res_contact' with column name

children(pid,pnochild,pcname,pcblood,pcdob)
occup_contact(pid,poccup_nature,poccup_type,poccup_add,pemail,poccup_phone,poccup_mobile)
personal(pid,pname,pfname,pmname,pfhname,pdob,pgender,pedulvl,pedu,pblood,gotra,panth,pmarritalstatus)
res_contact (pid,pres_add,pres_phone,pres_mobile)
spouse (pid,psname,psedulvl,psedu,psblood,psdob)

then on my form i dragged a data grid view in that i want to join results of all these these tables with modified column name like for

name not 'pname' it should be Name
fathername not 'pfname' it should be Father's Name........so on

and which select statement should i use to get join result of all tables based on the name of the person ie pname column of personal table where pid column of personal table is the primary key and used as foreign key in all other tables. All tables are dependent on personal table

I have used this

 cmd.CommandText = "select p.pname as 'Name',p.pfname as 'Father Name' ,p.pmname as 'Mother Name',p.pfhname as 'Family Head Name',p.pdob as 'Date of Birth',p.pgender as 'Gender',p.pedulvl as 'Education',p.pedu as 'Degree',p.pblood as 'Blood Group',p.gotra as 'Gotra',p.panth as 'Panth',p.pmarritalstatus as 'Marrital Status',s.psname as 'Spouse Name',s.psedulvl as 'Spouse Edu. Degree',s.psedu as 'Spouse Education',s.psblood as 'Spouse Blood Group',s.psdob as 'Spouse Date of Birth',c.pnochild as 'Number of Children',c.pcname as 'Child Name',c.pcblood as 'Child Blood Group',c.pcdob as 'Child Date of Birth',r.pres_add as 'Resident Address',pres_phone as 'Resident Ph.no ',pres_mobile as 'Resident Mobile no.',o.poccup_nature as 'Nature of Occupation',o.poccup_type as 'Type of Occupation',o.poccup_add as 'Office Address',o.pemail as 'Email id',o.poccup_phone as 'Office Ph.no',o.poccup_mobile as 'Office Mobile number'from personal as p join spouse as s on p.pid=s.pid join children as c on p.pid=c.pid join occup_contact as o on p.pid=o.pid join res_contact as r on p.pid=r.pid where pname='" + viewtxt.Text + "' "; 

在选择语句中使用alais名称Ex:从以下内容中选择pname作为“名称”:

您可以使用“添加列”向导并将其HeaderText属性(作为要显示为列标题文本的名称)和“ DataPropertyName字段”作为表列名称添加到datagridview中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM