'mods.hasrows(string)':并非所有代码路径都返回值 [英] 'mods.hasrows(string)':not all code path return a value

查看:73
本文介绍了'mods.hasrows(string)':并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我在类mods下声明了一个函数hasrows.
但它显示错误,即''.mods.hasrows(string)'':并非所有代码路径都返回值

Hello,
i have declare one function hasrows under a class mods.
but its showing error i.e.''mods.hasrows(string)'':not all code path return a value

public bool hasrows(string qry)
   {
       try {
           bool boo = false;
           OleDbCommand c = new OleDbCommand(qry, con);
           conn();
           OleDbDataReader reader = c.ExecuteReader();
           if (reader.HasRows == true) {
               reader.Close();
               boo = true;
           } else {
               reader.Close();
               boo = false;
           }
           c.Dispose();
           return (boo);
       } catch (Exception ex) {
           //MsgBox(ex.Message)

       }

   }

推荐答案

您必须在catch中或catch外部指定一个返回值,以便在发生异常时代码路径有效.
You have to specify a return value in your catch or outside your catch so the code path is valid when an exception occurs.
...
       catch (Exception ex) {
           //MsgBox(ex.Message)
           return false; // use this 
       }
     return false; // or this
 }


这篇关于'mods.hasrows(string)':并非所有代码路径都返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆