cannot convert from 'string' to 'system.datetime'

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have a drop down that is showing dates, I need to pass the selected date
to my proc, so I pass it like this;

getCarSales(Convert.ToDateTime(carTimeFrame.selectedItem.value).ToShortDateString());

but when i compile I'm getting the error"
'cannot convert from 'string' to 'system.datetime'

even if i hard code a date i'm getting this error. Now the getCarSales
method as the date as

public DataTable getCarSales(DateTime startDate, DateTime endDate)
{
call's the stored procedure
}
why am i getting this error and ow can i fix it?
 
The reason you are getting this error is because the ToShortDateString()
method returns a String, not a DateTime. Therefore you are actually passing
a String rather than a DateTime. I also want to notify you that in case you
haven't already noticed your getCarSales() method uses two parameters, but
in your example you only pass one (you are not seeing an error for this yet
because you are running into the typecasting error first).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top