gpt4 book ai didi

c# - 如何阻止 oracledatareader 读取

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:42 24 4
gpt4 key购买 nike

我已经创建了一个软件来从 Oracle DB 读取数据并通过 SMS 发送它,但是当我按下键盘上的 C 键时我想停止 datareader 读取,但是当我这样做时我收到了这个异常消息:

Operation is not valid due to the current state of the object

堆栈跟踪:

at Oracle.DataAccess.Client.OracleDataReader.Read()
at Test_SMS_AT_Command.Program.OnTimer(Object obj, EventArgs args)

这是我的代码:

   oraCommand.ExecuteNonQuery();

OracleDataAdapter oraDataAdapter = new OracleDataAdapter(oraCommand);
Oracle.DataAccess.Types.OracleRefCursor refCursor = (Oracle.DataAccess.Types.OracleRefCursor)oraParameter.Value;
OracleDataReader reader = refCursor.GetDataReader();
while (reader.Read())
{
if (cki.Key == ConsoleKey.C)
{
cancel();

if (reader != null)
{
reader.Close(); //Closed
}

break;

}

if (sms.sendSms(reader["MOBILE_NO"].ToString(), reader["TEXT"].ToString()))
{
Console.WriteLine("Message successfully sent to " + reader["MOBILE_NO"].ToString() + ": " + DateTime.Now);
setStatus(Convert.ToInt32(reader["GORANNET_SMS_ID"]));
writeToFile(reader["TEXT"] + " sent to " + reader["MOBILE_NO"] + " at: " + DateTime.Now);
}
else
{
Console.WriteLine("Message was not sent");
}
System.Threading.Thread.Sleep(15000);
}

谢谢

最佳答案

调用reader.Close();在 while 语句之后...

关于c# - 如何阻止 oracledatareader 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com