c# - MVC 4 Flush/Empty/Clear DataTable -
c# - MVC 4 Flush/Empty/Clear DataTable -
can please explain why clear()
or dispose()
fail flush datatable recordset?
i using datatable in mvc 4 project var tbl = new datatable()
working fine retrieving data, reason when utilize tbl.clear()
, tbl.dispose()
, effort reuse tbl
still has recordset previous query, why?
can please allow me know how flush/clear/empty previous datatable recordset?
any help much appreciated :-)
please see illustration code below:
string name = ""; string password = ""; var stringwriter = new stringwriter(); var author = new xmltextwriter(stringwriter) { formatting = formatting.indented }; var tbl = new datatable(); string strconn = webconfigurationmanager.connectionstrings["testconnection"].tostring(); var conn = new sqlconnection(strconn); using (conn) { conn.open(); var cmd = new sqlcommand("getuserloginid", conn) {commandtype = commandtype.storedprocedure}; cmd.parameters.addwithvalue("@uid", uid); cmd.parameters.addwithvalue("@bid", bid); var userrecord = new sqldataadapter(cmd); userrecord.fill(tbl); conn.close(); if (tbl.rows.count > 0) { var row = tbl.rows[0]; name = row["name"].tostring(); password = row["password"].tostring(); code = row["code"].tostring(); } tbl.clear(); tbl.dispose(); cmd = new sqlcommand("getuserdetails", conn) { commandtype = commandtype.storedprocedure }; cmd.parameters.addwithvalue("@code", code); cmd.parameters.addwithvalue("@bid", bid); userrecord.fill(tbl); if (tbl.rows.count > 0) { var row = tbl.rows[0]; writer.writestartdocument(); writer.writestartelement("root"); writer.writeelementstring("bid", row["bid"].tostring()); writer.writeelementstring("name", name); } else { writer.writestartdocument(); writer.writestartelement("root"); writer.writeelementstring("bid", "error"); } writer.writeendelement(); writer.flush(); writer.close(); }
seems utilize same sqldataadapter
. created new command :
cmd = new sqlcommand("getuserdetails", conn) { commandtype = commandtype.storedprocedure };
but have set userrecord new command:
userrecord = new sqldataadapter(cmd);
c# asp.net-mvc-4 datatable
Comments
Post a Comment