OleDbDataReader 关闭的问题

pd00 2009-03-31 02:03:41
OleDbTransaction oleTrans = null;
OleDbDataReader ReaderSelectSP = null;

try
{
OleDbCommand oleCommandSelectSP = new OleDbCommand();
oleCommandSelectSP.Connection = oleConnectionDB;
oleCommandSelectSP.CommandText = "sp_test001";;
oleCommandSelectSP.CommandType = CommandType.StoredProcedure;
oleCommandSelectSP.Transaction = oleTrans;

ReaderSelectSP = oleCommandSelectSP.ExecuteReader();

ReaderSelectSP.Close();
}
catch(Exception)
{
oleTrans = null;
throw;
}
finally
{

}


请问当执行sp(ReaderSelectSP = oleCommandSelectSP.ExecuteReader();)出错的时候,为什么不会跳到catch里面,而是执行ReaderSelectSP.Close();的时候报错,然后跳到catch里面,请高手指教,谢谢。
...全文
100 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pd00 2009-03-31
  • 打赏
  • 举报
回复
那我要在sp执行正常的时候,在下面接着写代码,比如一些赋值之类的操作,我想让他在sp执行出错的时候跳到catch,不去执行下面的程序
请问为什么执行sp出错的时候不会跳到catch里面?
itcrazyman 2009-03-31
  • 打赏
  • 举报
回复
一般情况下,我把ReaderSelectSP.Close(); 放到catch里一个,放到finally一个,你试下

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧