[英]Timer countdown sql, asp.net c#, javascript
I'm trying to write code of timer countdown with javascript, sql , c# , asp.net. 我正在尝试使用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: CS文件:
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 endTime中的行:2020/12/31 5:00 AM
and the result : NaN Days, NaN Hours, NaN Minutes, NaN Seconds. 结果:NaN天,NaN小时,NaN分钟,NaN秒。
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'. 当我将desgin从nvarchar(150)更改为datetime时,出现错误:无法将类型为System.DateTime的对象转换为类型为System.String的对象。
why i get the: NaN Days, NaN Hours, NaN Minutes, NaN Seconds. 为什么我得到:NaN Days,NaN Hours,NaN Minutes,NaN Seconds。
what is the probleme? 有什么问题? thanks.
谢谢。
To start, you need to change 首先,您需要更改
TargetDate = "document.forms[0].auctionEndDate.value";
to 至
TargetDate = document.forms[0].auctionEndDate.value;
what i need to do to avoid the error when i change the type from nvarchar to datetime ?
当我将类型从nvarchar更改为datetime时,我需要做些什么来避免错误?
Taking a guess here, since I'm really not a .NET programmer, you need to change 在这里猜测一下,因为我实际上不是.NET程序员,所以您需要进行更改
string tDate = (string)command.ExecuteScalar();
to 至
DateTime tDate = (DateTime) command.ExecuteScalar();
You can call GetType()
on the return value ExecuteScalar()
to see what type it really is. 您可以在返回值
ExecuteScalar()
GetType()
上调用GetType()
来查看其真正的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.