c# - GridView Table 1 related to Table 2 -
sorry know title confusing couldn't figure out put down.
basically created grid view queries database , displays data. works perfectly, no complain, have right is,
but want is,
question: not sure how can this, can point me out in right direction please ?
i think going use nested gridviews.
try change select
query below... expected result...
sql fiddle : http://www.sqlfiddle.com/#!3/00b5f/15
i have named table
fruits
select cratetitle,cratedescription,crateid, stuff( ( select ','+ [fruittitle] fruits crateid = t.crateid xml path('') ),1,1,'') types_of_fruits_in_crate (select distinct cratetitle,cratedescription,crateid fruits )t
or
create proc
*place query in proc*
*call proc*
*assign result set gridview*
you can assign stored proc result set gridview using below code :
datatable dt = new datatable(); sqlconnection connection = new sqlconnection("your connection string"); try { connection.open(); string spname = "yourstoredprocudurename"; sqlcommand sqlcmd = new sqlcommand(spname, connection); sqldataadapter sqlda = new sqldataadapter(sqlcmd); sqlcmd.commandtype = commandtype.storedprocedure; sqlda.fill(dt); if (dt.rows.count > 0) { //display datatable data control gridview example gridview1.datasource = dt; gridview1.databind(); } } catch (system.data.sqlclient.sqlexception ex) { string msg = "fetch error:"; msg += ex.message; throw new exception(msg); } { connection.close(); }