locked
How to bind a date picker to submit a date to a database record RRS feed

  • Question

  • User1007306150 posted

    Hi Guys

    Can anyone help me with this. Basically I have a list of form fields including a date picker option. I want to submit insert all these fields into a database record however I am struggling with the date picker field.  Please review the code:

    Input for the Date Picker

     <input type="date" class="form-control" name="date" value="@Request.Form["datepicker"]" />

    Inserting the fields into a new database record

    if(IsPost){
           
           var serverid = Request["ServerID"].AsInt();
           var customerid = Request["CustomerID"].AsInt();
           var date = Request.Form["datepicker"];
           var status = Request["status"];
           var details = Request["details"];
           
    
            var db2 = Database.Open("BackupMonitoringAppV2") ;
            var insertCommand = "INSERT INTO Backups (ServerID, CustomerID, Date, Status, Details) VALUES(@0, @1, @2, @3, @4)";
            db.Execute(insertCommand, serverid, customerid, date, status, details);
            Response.Redirect("~/Dashboard/Servers");
    
    
           
         
        };

    Thanks!

    Tuesday, July 12, 2016 10:05 AM

All replies

  • User379720387 posted

    All looks good, except:

    value="@Request.Form["datepicker"]"
    value="@valuefromdbtopopulatedatepickertextbox"

    Tuesday, July 12, 2016 11:17 AM
  • User1007306150 posted

    Thanks for you reply, however my original code in the first post worked fine.

    Tuesday, July 12, 2016 7:06 PM
  • User379720387 posted

    ok, what is your question then?

    Tuesday, July 12, 2016 7:34 PM