I’m trying to write code of timer countdown with javascript, sql , c# , asp.net.
the code now is like that:
<input type="text" id="auctionEndDate" value="<%=TargetDate()%>" style="display:none"/>
<script language="JavaScript" type="text/javascript">
TargetDate = "document.forms[0].auctionEndDate.value";
/*this is a property in code behind*/BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "the auction end"
</script>
<script type="text/javascript" language="JavaScript"
src="http://scripts.hashemian.com/js/countdown.js"></script>
</script>
cs file:
public string TargetDate()
{
SqlConnection connection = new SqlConnection("Data Source=tcp:***.*****.com;Initial Catalog=DB_***_****;User ID=***_*****_****_user;Password=******;Integrated Security=False;");
string commandtext = "SELECT endTime FROM Timer";
SqlCommand command = new SqlCommand(commandtext, connection);
connection.Open();
string tDate = (string)command.ExecuteScalar();
connection.Close();
return tDate;
}
Timer table desgin:
===============
id
endTime (nvarchar (150)
row in endTime : 12/31/2020 5:00 AM
and the result : NaN Days, NaN Hours, NaN Minutes, NaN Seconds.
when i change the desgin from nvarchar(150) to datetime i get the error : Unable to cast object of type ‘System.DateTime’ to type ‘System.String’.
why i get the: NaN Days, NaN Hours, NaN Minutes, NaN Seconds.
what is the probleme? thanks.
To start, you need to change
to
Taking a guess here, since I’m really not a .NET programmer, you need to change
to
You can call
GetType()on the return valueExecuteScalar()to see what type it really is.