我想在c#上編寫代碼,比較我對SQL表(表:項目,列「endTime」)和datetime.now以及結果 - 顯示圖像。在SQL表上比較Datetime.now
例如:
如果該列表中的時間是時間之前現在..所以顯示在ASPX image1的,否則顯示圖像2。
我試圖做到這一點的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);
但我有錯誤,但我相信這是來自回報。
我很抱歉,但'我error'是不是很描述您所遇到的問題。 –
「我得到了錯誤」與你所能得到的一樣模糊,並且帶來了糟糕的英語。什麼錯誤/什麼行/等等。 – Coeffect
這段代碼不完整,沒有意義... – gbn