2011-05-22 105 views
0

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

现在的代码是这样的:

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

定时器DESGIN表:

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

id 

endTime (nvarchar (150) 

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

和结果:NaN Days,NaN小时,NaN分钟,NaN秒。

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

为什么我得到:NaN Days,NaN Hours,NaN Minutes,NaN Seconds。

问题是什么?谢谢。

回答

0

要开始,你需要改变

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

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

什么,我需要做的,以避免错误,当我从nvarchar的类型更改为日期时间?

以猜测在这里,因为我真的不是一个.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.

+0

宾果!!!!喝彩! – Oshrib 2011-05-22 14:42:20

+0

我需要做什么来避免错误,当我从nvarchar类型更改为datetime? – Oshrib 2011-05-22 15:12:05

+0

@Bside看到我的编辑。 – 2011-05-22 15:15:30