Casting string to date in VB.NET
I am passing a date field to an SQL database.
The field is declared as String
in the VB.NET application.
I wrote a piece of code for casting to Date
:
Dim dtBdate As Date
If param_strDOB <> String.Empty Then
dtBdate = Convert.ToDateTime(param_strDOB)
End If
But the value is passed as #3/11/2011#
. It has a #
- sign on either side of the Date Field.
How do I fix it?
In the SQL database the stored procedu开发者_Go百科re takes the input parameter as " @DOB DateTime ".
From MSDN:
The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters '#'
So you should be able to convert/parse as-is.
Where are you seeing the #
s? While looking at it in Visual Studio? If so, then it's just the debugger showing that it's a Date
value. Just ignore them.
Quote:
However, the compiler treats literals enclosed within number signs (# #) as Date.
精彩评论