I am using the followig code:
SqlConnection con = new SqlConnection(strcon);
con.Open();
string strSelect = "Select PaidUntil from Users where username='" + un +
"'";
SqlCommand cmd = new SqlCommand(strSelect, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
dr.Read();
DateTime PaidUntil;
PaidUntil = DateTime.Parse(dr.GetValue(0));
if (PaidUntil < DateTime.Now)
The problem is with the line where I am trying to declare the PaidUntil
local variable. I get the error:
Compiler Error Message: CS1502: The best overloaded method match for
'System.DateTime.Parse(string)' has some invalid arguments
Also, I have not got to the comparison part, but is that correct or should I
be using something like:
DateTime.Compare(PaidUntil, DateTimeNow())
Thanx for your help.

Signature
Anil Gupte
www.keeninc.net
www.icinema.com
Just Me - 29 Mar 2008 18:37 GMT
You need to step through the code in debug. but you should try adding
.ToString() to your dr.GetValue(0), this may help. You need to know though
that your object is not null.
>I am using the followig code:
>
[quoted text clipped - 19 lines]
>
> Thanx for your help.
Peter Duniho - 29 Mar 2008 18:50 GMT
> [...]
> PaidUntil = DateTime.Parse(dr.GetValue(0));
[quoted text clipped - 3 lines]
> Compiler Error Message: CS1502: The best overloaded method match for
> 'System.DateTime.Parse(string)' has some invalid arguments
You probably just need to cast the result from GetValue() to a string.
GetValue() returns an object reference, not a string.
Of course, it goes without saying that if you expect this code to work,
the actual object had better actually be a string. If not, you have some
additional conversion to do.
The comparison looks fine, but why bother asking about it until you have
problems?
Pete
thomasnguyencom - 29 Mar 2008 18:51 GMT
> I am using the followig code:
>
[quoted text clipped - 22 lines]
> --
> Anil Guptewww.keeninc.netwww.icinema.com
I've used:
DateTime PaidUntil = System.Convert.ToDateTime(someObject);
Also, keep in mind for comparing, the entire DateTime object contains
the both the Date and Time. Otherwise, be sure to get just the
PaidUntil.Date. I've busted myself a few times on that one.
Good luck,
-tom