sql - VB.net Query on Datagrid view -
i need display value in datagrid not id. have 2 tables table1, having empid, receivedbyid, releasebyid, id's refer on table2 whereby table2 having id, name.
i required display on datagrid table1 respected name not id. ex table1 id's 1,3,3 table2 data is, 1 - name1, 2 - name2, 3-name3
output should be,
name1, name3, name3
for c#
stringbuilder sb = new stringbuilder(); sb.appendline(" select b.name empname,c.name receivedby,d.name releasedby table1 "); sb.appendline(" inner join table2 b on a.empid = b.id "); sb.appendline(" inner join table2 c on a.receivedbyid = b.id "); sb.appendline(" inner join table2 d on a.releasebyid = b.id "); sqlconnection conn = new sqlconnection(myconstring); sqlcommand cmd = new sqlcommand(sb.tostring(), conn); conn.open(); datatable datatable = new datatable(); sqldataadapter da = new sqldataadapter(cmd); da.fill(datatable); gridview.datasource = datatable; gridview.databind();
for vb
dim sb new stringbuilder() sb.appendline(" select b.name empname,c.name receivedby,d.name releasedby table1 ") sb.appendline(" inner join table2 b on a.empid = b.id ") sb.appendline(" inner join table2 c on a.receivedbyid = b.id ") sb.appendline(" inner join table2 d on a.releasebyid = b.id ") dim conn new sqlconnection(myconstring) dim cmd new sqlcommand(sb.tostring(), conn) conn.open() dim datatable new datatable() dim da new sqldataadapter(cmd) da.fill(datatable) gridview.datasource = datatable gridview.databind()
this code you.
Comments
Post a Comment