请大家帮个忙,看看这个代码,在catch中应该写什么啊
我是想测试我的数据库中有没有这样的记录,我自己定义了个类,然后里面写了个方法,但是老说“并非所有代码都返回值”,这改怎么写啊public bool addTeacher (string name)
{
string connstr = ConfigurationManager.ConnectionStrings["OleDBconnstr"].ConnectionString;
string strcomm = "select teacname from teacher where teacname=" + "'" + name + "'";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand comm = new OleDbCommand(strcomm, conn);
conn.Open();
OleDbDataReader read = comm.ExecuteReader();
conn.Close();
try
{
if (read.HasRows)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
}
}