c# - i m not getting my insert query running in my sql database -
protected void button1_click1(object sender, eventargs e) { try { conn.open(); string idquery = "select top 1 pid post order pid desc "; cmd = new sqlcommand(idquery, conn); sqldatareader reader = cmd.executereader(); reader.read(); string p1id = (reader["pid"].tostring()); int pid = convert.toint32(p1id); textbox3.text = (reader["pid"].tostring()); conn.close(); sqlconnection conn1 = new sqlconnection(configurationmanager.connectionstrings["registrationconnectionstring"].connectionstring); string insertquery = "insert post (pid ,pidtype ,title ,question,creationdate) values (@pid,@ptype,@title,@question,@cdate)"; com = new sqlcommand(insertquery, conn1); datetime = datetime.now; ++pid; com.parameters.addwithvalue("@pid", pid); com.parameters.addwithvalue("@ptype", 1); com.parameters.addwithvalue("@title", textbox2.text); com.parameters.addwithvalue("@question", textarea1.text); com.parameters.addwithvalue("@cdate", now); response.write("successfull"); response.redirect("questions.aspx"); conn1.close(); } catch (exception ex) { response.write("error" + ex.tostring()); } }
this code i've written..its not giving error or exception...bt data not getting inserted database
you need call exectenonquery
, afte adding parameters:-
com.exectenonquery();
Comments
Post a Comment