asp.net - On Click Twice the Button Shows "ConnectionString property has not been initialized" -
i have following code:
using system; using system.collections.generic; using system.data.sqlclient; using system.data; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class supervissions_pages_jwelorder : system.web.ui.page { #region variable classdata clsdt = new classdata(); sqldataadapter da; dataset ds; #endregion #region events protected void page_load(object sender, eventargs e) { if (!ispostback) { bindgrid(); } session["mbrid"] = "lym47336163"; } protected void grdview_rowcancelingedit(object sender, gridviewcancelediteventargs e) { grdview.editindex = -1; bindgrid(); } protected void grdview_rowcommand(object sender, gridviewcommandeventargs e) { if (e.commandname.equals("add")) { dropdownlist item = (dropdownlist)grdview.footerrow.findcontrol("ddlparticular_f"); textbox quantity = (textbox)grdview.footerrow.findcontrol("txtquantity_f"); textbox rate = (textbox)grdview.footerrow.findcontrol("txtrate_f"); textbox serialcode = (textbox)grdview.footerrow.findcontrol("txtserial_f"); addjwelorder(txtmbrid.text, txtdate.text, item.text, quantity.text, rate.text, serialcode.text); grdview.editindex = -1; bindgrid(); } } protected void grdview_rowdeleting(object sender, gridviewdeleteeventargs e) { } protected void grdview_rowediting(object sender, gridviewediteventargs e) { grdview.editindex = e.neweditindex; bindgrid(); dropdownlist item = (dropdownlist)grdview.footerrow.findcontrol("ddlparticular_f"); ddparticular(item); } protected void grdview_rowupdating(object sender, gridviewupdateeventargs e) { } protected void txtmbrid_textchanged(object sender, eventargs e) { using (clsdt.sqlcnn) { clsdt.sqlcnn.open(); sqlcommand cmd = new sqlcommand("select mbr_nm mbr_mst mbr_id = @name", clsdt.sqlcnn); cmd.parameters.add("@name", txtmbrid.text); datatable dtt = new datatable(); string strname = (string)cmd.executescalar(); if (!string.isnullorempty(strname)) { txtmbrnm.text = strname; } } } protected void txtdate_textchanged(object sender, eventargs e) { bindgrid(); } protected void grdview_rowcreated(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.footer) { var particular = e.row.findcontrol("ddlparticular_f") dropdownlist; if (null != particular) { ddparticular(particular); } } } #endregion #region functions 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(); datatable dt = new datatable(); dt.load(cmd.executereader()); grdview.datasource = dt; grdview.databind(); } } protected void addjwelorder(string strmemberid, string strdate, string strparticular, string strquantity, string strrate, string serialcode) { using (clsdt.sqlcnn) { clsdt.sqlcnn.open(); sqlcommand cmd = new sqlcommand("usp_crud_jwelorders", clsdt.sqlcnn); cmd.parameters.add(new sqlparameter("@operation", sqldbtype.varchar, 10)); cmd.parameters.add(new sqlparameter("@memberid", sqldbtype.varchar, 20)); cmd.parameters.add(new sqlparameter("@orderdt", sqldbtype.datetime)); cmd.parameters.add(new sqlparameter("@item", sqldbtype.varchar, 3)); cmd.parameters.add(new sqlparameter("@orderqty", sqldbtype.varchar,20)); cmd.parameters.add(new sqlparameter("@rte", sqldbtype.varchar, 8)); cmd.parameters.add(new sqlparameter("@serealcode", sqldbtype.varchar, 20)); cmd.parameters.add(new sqlparameter("@franchise_code", sqldbtype.varchar, 20)); cmd.parameters.add(new sqlparameter("@orderid", sqldbtype.varchar, 20)); cmd.parameters["@operation"].value = "add"; cmd.parameters["@memberid"].value = strmemberid; cmd.parameters["@orderdt"].value = strdate; cmd.parameters["@item"].value = strparticular; cmd.parameters["@orderqty"].value = strquantity; cmd.parameters["@rte"].value = strrate; cmd.parameters["@serealcode"].value = serialcode; cmd.parameters["@franchise_code"].value = session["mbrid"].tostring(); cmd.parameters["@orderid"].value = clsdt.getdatatable("select right(1000000+(max(jwl_orid) + 1),6) orderid jwl_ord_mst").rows[0][0].tostring(); cmd.commandtype = commandtype.storedprocedure; da = new sqldataadapter(cmd); ds = new dataset(); da.fill(ds); } } 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(); } protected void delete(string id) { using (clsdt.sqlcnn) { clsdt.sqlcnn.open(); sqlcommand cmd = new sqlcommand("usp_crud_jwelorders", clsdt.sqlcnn); cmd.parameters.add(new sqlparameter("@operation", sqldbtype.varchar, 10)); cmd.parameters.add(new sqlparameter("@si", sqldbtype.int)); cmd.parameters["@operation"].value = "delete"; cmd.parameters["@si"].value = id; cmd.commandtype = commandtype.storedprocedure; da = new sqldataadapter(cmd); ds = new dataset(); da.fill(ds); } } protected void updatemail(string strsi, string strparticular, string strquantity, string strrate, string serialcode) { using (clsdt.sqlcnn) { clsdt.sqlcnn.open(); sqlcommand cmd = new sqlcommand("usp_crud_jwelorders", clsdt.sqlcnn); cmd.parameters.add(new sqlparameter("@operation", sqldbtype.varchar, 10)); cmd.parameters.add(new sqlparameter("@item", sqldbtype.varchar, 3)); cmd.parameters.add(new sqlparameter("@orderqty", sqldbtype.int)); cmd.parameters.add(new sqlparameter("@rte", sqldbtype.varchar, 8)); cmd.parameters.add(new sqlparameter("@serealcode", sqldbtype.varchar, 20)); cmd.parameters.add(new sqlparameter("@si", sqldbtype.int)); cmd.parameters["@operation"].value = "update"; cmd.parameters["@item"].value = strparticular; cmd.parameters["@orderqty"].value = strquantity; cmd.parameters["@rte"].value = strrate; cmd.parameters["@serealcode"].value = serialcode; cmd.parameters["@si"].value = strsi; cmd.commandtype = commandtype.storedprocedure; da = new sqldataadapter(cmd); ds = new dataset(); da.fill(ds); } } #endregion }
and design is:
the problem when click add button first time data saved sucessfully... second time when click add button shows me error below.
classdata code is:
imports microsoft.visualbasic imports system.data.sqlclient imports system.data public class classdata private sqlstring string private com sqlcommand private dmlstring string private sqldr sqldatareader public sqlcnn new sqlconnection(configurationmanager.connectionstrings("constring").tostring()) public function getrandomval() string dim str string dim rnd new random str = rnd.next(111111, 999999) return str end function public function getdatatable(byval qry string) datatable if sqlcnn.state <> connectionstate.open sqlcnn.open() dim sqlcmd new sqlcommand(qry, sqlcnn) dim dt new datatable ' dim sqldt new sqldataadapter(qry, sqlcnn) ' com.connection = sqlcnn sqlcmd.commandtimeout = 150000 sqldr = sqlcmd.executereader() ' sqldt.fill(dt) dt.load(sqldr) sqldr.close() if sqlcnn.state = connectionstate.open sqlcnn.close() return dt end function public function executequery(byval strqry string) integer if sqlcnn.state <> connectionstate.open sqlcnn.open() dim sqlcmd new sqlcommand(strqry, sqlcnn) sqlcmd.commandtimeout = 1500 ' com.connection = sqlcnn 'com.commandtimeout = 15000 'sqldr = sqlcmd.executereader() dim int = sqlcmd.executenonquery() if sqlcnn.state = connectionstate.open sqlcnn.close() return int end function 'public function executequery(byval strqry string) datatable ' dim dt new datatable ' if sqlcnn.state <> connectionstate.open sqlcnn.open() ' dim sqlcmd new sqlcommand(strqry, sqlcnn) ' dt = sqlcmd.executereder() ' if sqlcnn.state = connectionstate.open sqlcnn.close() ' return 'end function end class
Comments
Post a Comment