【问题标题】:Timer countdown sql, asp.net c#, javascript定时器倒计时 sql, asp.net c#, javascript
【发布时间】:2011-05-22 14:37:06
【问题描述】:

我正在尝试使用 javascript、sql、c#、asp.net 编写计时器倒计时代码。

现在的代码是这样的:

<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 文件:

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;
}

定时器表设计:

 ===============

 id

 endTime (nvarchar (150)

行结束时间:12/31/2020 5:00 AM

结果:NaN 天、NaN 小时、NaN 分钟、NaN 秒。

当我将设计从 nvarchar(150) 更改为 datetime 时,我收到错误:无法将“System.DateTime”类型的对象转换为“System.String”类型。

为什么我得到:NaN 天、NaN 小时、NaN 分钟、NaN 秒。

有什么问题?谢谢。

【问题讨论】:

    标签: c# javascript asp.net sql


    【解决方案1】:

    要开始,你需要改变

    TargetDate = "document.forms[0].auctionEndDate.value";
    

    TargetDate = document.forms[0].auctionEndDate.value;
    

    当我将类型从 nvarchar 更改为 datetime 时,我需要做些什么来避免错误?

    在这里猜一猜,由于我真的不是.NET程序员,你需要改变

    string tDate = (string)command.ExecuteScalar();
    

    DateTime tDate = (DateTime) command.ExecuteScalar();
    

    You can call GetType() on the return value ExecuteScalar() to see what type it really is.

    【讨论】:

    • 当我将类型从 nvarchar 更改为 datetime 时,我需要做些什么来避免错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多