当我在计时器中调用此函数时,它会一直告诉我 连接未关闭,连接的当前状态已打开
任何帮助请...
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();
}
}
答案 0 :(得分:2)
如消息所示,您的连接已打开。这意味着您已经调用了
connection.Open();
在调用“通知”之前的某个地方。检查您的代码,看看是否是这种情况。希望它有所帮助。