开放时,我调用这个函数在计时器的都跟我说 的连接并没有关闭连接的当前状态是开放的连接并没有关闭连接的当前状态为C#
任何帮助,请...
public static void Notify(string source, string query, ref OleDbConnection connection)
{
OleDbCommand command = new OleDbCommand(query, connection);
try
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
DateTime date = DateTime.Parse(reader[0].ToString());
if (date.ToShortDateString() == DateTime.Now.ToShortDateString())
{
DateTime time = DateTime.Parse(reader[1].ToString());
if (time.ToShortTimeString() ==DateTime.Now.ToShortTimeString())
{
string notification = source + " You have " + reader[2].ToString() + " at " + (time.ToLongTimeString()).ToString();
MessageBox.Show(notification, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
在哪一行? – tchelidze
您是否在其他地方使用连接?你提供它作为参数,所以也许它不是唯一一次使用它? – Karl
有没有错误的语法,它只是当时间是正确的(等于时间.now) 其重复的消息为60秒多, 它告诉我,我会停止时间不正确 –