当我在计时器中调用这个函数时,它一直告诉我连接没有关闭连接的当前状态是打开的
任何帮助请...
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();
}
}
正如消息所说,您的连接已经打开。这意味着您已经调用了
connection.Open();
在调用“通知”之前的某个地方。检查您的代码,看看是否是这种情况。希望能帮助到你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句