locked
Insert Detailsview with custom values RRS feed

  • Question

  • User56474492 posted

    I'm using a Detailsview. When user updates data, I want to save the current date in my Database.

    Current UpdateCommand is:

    UpdateCommand="UPDATE Kunde SET Anrede = @Anrede, Vorname = @Vorname, Nachname = @Nachname, Strasse = @Strasse, Postleitzahl = @Postleitzahl, Geschlecht = @Geschlecht, Stadt = @Stadt, Geburtstag = @Geburtstag WHERE ([ID] = @ID)"

    How do I insert something like

    UpdateCommand="UPDATE xyz SET dateXYZ = DateTime.Now WHERE ([ID] = @ID)"

    Friday, September 30, 2011 5:08 AM

Answers

  • User-126497635 posted
     <asp:SqlDataSource ID="SqlDataSourceID" runat="server">
            <UpdateParameters>
            <asp:Parameter Name="Date" Type="DateTime" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    
     protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataSourceID.UpdateParameters["Date"].DefaultValue = DateTime.Now.ToString();
          
        }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 5:18 AM

All replies

  • User699558600 posted

    Here is the way if you use any Data source control

     <asp:SqlDataSource ID="ListDataSource" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" UpdateCommand=="UPDATE xyz SET dateXYZ = @LocalDateTime WHERE ([ID] = @ID)" runat="server">
            <UpdateParameters>
                <asp:Parameter Name="ID" />
                <asp:Parameter Type="DateTime" Name="LocalDateTime" />
            </UpdateParameters>
         </asp:SqlDataSource>
     
    and set its value on Page Load like this
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    
                ListDataSource.UpdateParameters["LocalDateTime"].DefaultValue = DateTime.Now.ToString();
            }
    }
    Friday, September 30, 2011 5:16 AM
  • User-126497635 posted
     <asp:SqlDataSource ID="SqlDataSourceID" runat="server">
            <UpdateParameters>
            <asp:Parameter Name="Date" Type="DateTime" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    
     protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataSourceID.UpdateParameters["Date"].DefaultValue = DateTime.Now.ToString();
          
        }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 5:18 AM
  • User56474492 posted

    Thank you Smile

    Friday, September 30, 2011 5:30 AM