Too many arguments error
Hi i'm getting an error when using this code
Ses开发者_如何转开发sion("formatdate") = Left(drv.Row("booking_status"), 10)
Session("formatdate").ToString("dd-MMM-yyyy")
Can anyone suggest anything? I'm trying to convert my session to a friendly date format but it won't work
This is the error
Too many arguments to 'Public Overridable Function ToString() As String'.
Thanks
Jamie
Left(drv.Row("booking_status"), 10)
returns a String.
There is no overload for String.ToString() that takes a String as a parameter. You might want to try something like:
Session("formatdate") = DateTime.Parse(Left(drv.Row("booking_status"), 10)) _
.ToString("dd-MMM-yyyy");
I used a tool to convert from C# to VB, so here you go...
Dim formattedDate As String = [String].Format("{0:C}", Session("formatdate"))
As Justin pointed out, there is no overload for String.ToString()
that takes a string as a parameter. However, there are several overloads for DateTime.ToString()
, one of which does take a string.
In order to take advantage of this method, you need to convert your Session("formatdate")
to a DateTime
object:
Session("formatdate") = Left(drv.Row("booking_status"), 10) = Left(drv.Row("booking_status"), 10)
DateTime temp;
// Ensure date parsed successfully
if (DateTime.TryParse(Session("formatdate"), out temp)
{
string formattedDate = temp.ToString("dd-MMM-yyyy");
}
Note that if you know the format that Session("formatdate")
will be in, you can use DateTime.TryParseExact()
instead of just TryParse()
to ensure that the date is parsed according to the proper format.
You need to store a DateTime in Session("formatdate") then use ((DateTime) Session("formatdate")).ToString("dd-MM-yyyy");
精彩评论