locked
Using a stored procedure with ADO.net RRS feed

  • Question

  • User-1352156089 posted

    Hi All,

    I need to populate 2 textboxes with 2 dates in the onload event of my page using ADO.net in code behind. 

    I translated the following SQL query

    declare @Today datetime
    declare @LastAvailableDay datetime
    set @Today = getdate()
    set @LastAvailableDay = dateadd(day,+29, @Today)
    SELECT DISTINCT @Today, @LastAvailableDay FROM dbo.DateTable

    into the below Stored Procedure:

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE getOnloadDates 
    @Today datetime,
    @LastAvailableDay datetime
    AS
    BEGIN
    SET NOCOUNT ON;
    SELECT DISTINCT @Today, @LastAvailableDay FROM dbo.DateTable
    END
    GO

    How would you suggest in ADO to specify that @Today should be "getdate()" and @LastAvailableDate should be "dateadd(day,+29, @Today)"?

    @Today and @LastAvailableDate should fill the 2 textboxes.

    Thank you in advance,
    Claudio

    Wednesday, February 13, 2019 7:34 PM

Answers

All replies

  • User475983607 posted

    How would you suggest in ADO to specify that @Today should be "getdate()" and @LastAvailableDate should be "dateadd(day,+29, @Today)"?

    Not ADO.NET.  .NET has the DateTime.AddDays() method.

    https://docs.microsoft.com/en-us/dotnet/api/system.datetime.adddays?view=netframework-4.7.2

    DateTime lastAvailableDate = DateTime.Now.AddDays(29);



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2019 7:45 PM
  • User-1352156089 posted

    Thanks,

    I used:

     Public Sub Test()
            Dim Today As DateTime = DateTime.Now.ToString("dd/MM/yyyy")
            Textbox1.Text = Today
            Dim lastAvailableDate As DateTime = DateTime.Now.AddDays(29).ToString("dd/MM/yyyy")
            Textbox2.Text = lastAvailableDate
        End Sub

    Thanks

    Wednesday, February 13, 2019 8:34 PM