manikandan r

manikandan r

  • NA
  • 358
  • 0

How to pass Date parameter in Request

Feb 17 2024 10:38 PM

Hi,

I want to write a Web API which has date pameter in Request. In Stored procedure this parameter is defined as Varchar. What do i define  my variable in Request entity? (datetime or string ??) 

I am getting this error below error.

“Unable to cast object of type 'System.String' to type 'System.DateTime'."

Request Model: 

public class Ticket{

public DateTime bookingDate { get; set; }

Response Model:

public class Booking
{

public string TickerNumber { get; set; } = string.Empty;

public string MovieName { get; set; } = string.Empty;

public Datetime ReleaseDate { get; set; } 

}

 

Stored Procedure:

CREATE PROC TICKETMASTER (

@bookingDate VARCHAR(10) = NULL

) AS 

BEGIN

SELECT * from TicketLib where ReleaseDate = @bookingDate

END


Answers (1)