Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

asked on

Returning a single date from a database

I need to return a date from a database.  I can't seem to get it to return.  this is what I have so far.  Can anyone help.  thanks

SqlConnection sqlConnection1 = new SqlConnection("MyConnectString");
SqlCommand cmd = new SqlCommand();
DateTime returnValue;

cmd.CommandText = "SELECT PollOpenTo from Polls.Dates";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

returnValue = cmd.ExecuteScalar();

sqlConnection1.Close();
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

what do you get in your returnValue variable? Any errors?
Avatar of sherbug1015

ASKER

i get an error that it can't convert ExecuteScalar to non-delegate type System.Datetime.  Did you intend to invoke a method
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial