asp.net - open DataReader associated with this Command which must be closed first -


the following code binding grid:

protected void bindgrid() {     using (clsdt.sqlcnn)     {         clsdt.sqlcnn.open();         sqlcommand cmd = new sqlcommand("usp_crud_jwelorders", clsdt.sqlcnn);         cmd.parameters.add(new sqlparameter("@operation", sqldbtype.varchar, 20));         cmd.parameters["@operation"].value = "display";         cmd.commandtype = commandtype.storedprocedure;         grdview.datasource = cmd.executereader();         grdview.databind();         clsdt.sqlcnn.close();     } } 

and following binding dropdown on same page:

protected void ddparticular(dropdownlist ddlparticular) {     datatable dt = new datatable();     ddlparticular.datasource = clsdt.getdatatable("select com_cmcd,com_cmnm com_mst com_cmcd = (select com_cmcd com_typ com_ctnm = 'jewellery')");     ddlparticular.datatextfield = "com_cmnm";     ddlparticular.datavaluefield = "com_cmcd";     ddlparticular.databind(); } 

but when running shows:

there open datareader associated command must closed first

the thing can see straight off bat binding grid view data reader, i'm not sure work (you have invoke reader.read() rows), may never read, , never close connection since reader isn't finished (i may wrong that).

out of interest, try replacing this:

grdview.datasource = cmd.executereader(); grdview.databind(); 

with:

var dt = new datatable(); var reader = cmd.executereader(); dt.load(reader); grdview.datasource = dt; grdview.databind(); 

i've had fair issues datareaders binding grid views, way now.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -