【发布时间】:2011-06-30 13:59:37
【问题描述】:
我正在尝试在 c# 上编写代码,将我在 SQL 表(表:项目,列“endTime”)上的日期与 datetime.now 和结果进行比较 - 显示图像。
示例:
如果列表上的时间早于现在的时间.. 则显示在 aspx image1 上,否则显示 image2。
我已经尝试通过 sql 命令来做到这一点:
private DateTime endTime(out int lastDate)
{
SqlConnection connection = new SqlConnection("Data Source=******;Initial Catalog=******;User ID=*****;Integrated Security=False;");
string commandtext = "SELECT TOP(1) endTime FROM items";
SqlCommand command = new SqlCommand(commandtext, connection);
connection.Open();
SqlCommand command2 = new SqlCommand(commandtext, connection);
lastDate = (int)command2.ExecuteScalar();
connection.Close();
return ...
}
但是我在返回和执行方法时遇到问题...:
int d;
Console.WriteLine(endTime(out d));
if (d < DateTime.Now)
{
image1.Visible = true;
}
else
{
image2.Visible = true;
}
Console.WriteLine(d);
但我得到了错误,但我相信它来自回报。
【问题讨论】:
-
很抱歉,
I got error无法很好地描述您遇到的问题。 -
“我有错误”的含义尽可能模糊,另外还有一个好处是英语很糟糕。什么错误/什么行/等等。
-
这段代码不完整,没有意义...
-
问题出在 vwd 上: if(d
-
@Mannimarco 谢谢你,但不是每个人的英语都像你一样好......我正在尽我所能写。谁可以尝试帮助我将不胜感激。
标签: c# asp.net sql sqlcommand