asp.net - Update SQL database with session parameter in C# -


i'm looking way update sql server database code-behind in c# session parameter, how sqlcommand in asp:

important: sqlcommand in c# in static function going problem ?

thanks in advance!

<asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:spms_dbconnectionstring1 %>"          updatecommand="update project set startdate = @startdate, duedate = @duedate, progress = @progress, status = @status (prid = @prid)">         <updateparameters>             <asp:sessionparameter name="prid" sessionfield="project" type="string" />             <asp:parameter name="startdate" type="datetime"/>             <asp:parameter name="duedate" type="datetime" />             <asp:parameter name="progress" type="int32" />             <asp:parameter name="status" type="boolean" />             <asp:parameter name="projectid" type="int32" />         </updateparameters>     </asp:sqldatasource> 

this how solved it:

    string connectionstring = system.configuration.configurationmanager.connectionstrings["spms_dbconnectionstring1"].connectionstring;     using (sqlconnection connection = new sqlconnection(connectionstring))     using (sqlcommand command = connection.createcommand())     {           datetime startdate = datefrommilisec(start);         datetime duedate = datefrommilisec(end);         int progress = convert.toint32(prog);         string prid = httpcontext.current.session["project"].tostring();                   command.commandtext ="update project set startdate = @startdate, duedate = @duedate, progress = @progress, status = @status (prid = @prid)";          command.parameters.addwithvalue("@startdate", startdate );         command.parameters.addwithvalue("@duedate", duedate );         command.parameters.addwithvalue("@progress", progress );         command.parameters.addwithvalue("@status", status );         command.parameters.addwithvalue("@prid", prid );          connection.open();         command.executenonquery();         connection.close();     }  

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -