连接到 sql、asp.net c# 的 javascript 出错
我有 javascript 计时器倒计时,代码如下:
<script language="JavaScript">
TargetDate = "<% = TargetDate %>";
/*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 language="JavaScript" src="countdown.js"></script>
</script>
后面的代码:
public string TargetDate ()
{
DataTable dataTable = new DataTable();
using (SqlConnection connection = new SqlConnection("Server=localhost;Database=Timer;Trusted_Connectopn=True"))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "select * from endTime";
connection.Open();
SqlDataReader reader = command.ExecuteReader();
dataTable.Load(reader); }
}
我收到错误: “t.TargetDate()”:并非所有代码路径都会返回值。
当我尝试写 return 时,我遇到了另一个错误...这意味着我不知道该怎么做:)
I have javascript timer countdown with the code:
<script language="JavaScript">
TargetDate = "<% = TargetDate %>";
/*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 language="JavaScript" src="countdown.js"></script>
</script>
the code behind:
public string TargetDate ()
{
DataTable dataTable = new DataTable();
using (SqlConnection connection = new SqlConnection("Server=localhost;Database=Timer;Trusted_Connectopn=True"))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "select * from endTime";
connection.Open();
SqlDataReader reader = command.ExecuteReader();
dataTable.Load(reader); }
}
i get the error:
't.TargetDate()': not all code paths return value.
when i tried to write return i got another error... what means that i dont know what to do :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您必须根据函数规范以字符串形式返回目标日期值。
您应该读取数据表并将其返回。像这样的东西
希望这有帮助。
First of all you must return the targetdate value as string according to your function specification.
You should read the datatable and return that. Something like this
Hope this helps.
你的方法应该返回字符串。事实并非如此。
public string TargetDate
没有
返回
。使用
ExecuteScalar
,而不是ExecuteReader
。返回字符串值。
Your method supposed to return string. It doesn't.
public string TargetDate
There is no
return
.Use
ExecuteScalar
, instead ofExecuteReader
.Return the string value.
您的连接字符串中还存在拼写错误:
Trusted_Connectopn
应为Trusted_Connection
You also have a spelling error in your connection string:
Trusted_Connectopn
should beTrusted_Connection