本文介绍了'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)':并非所有代码路径都返回值
发布评论