By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.select edItem.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?
May 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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).
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"John" <wh****@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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.select edItem.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?

Jun 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.