public DataSet FindOfName(EmployeesAttribute employees)
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connstr))
{
SqlParameter p = new SqlParameter("@emp_name", SqlDbType.VarChar);
p.Value = "%" + employees.Emp_name + "%";
SqlDataAdapter adapter = new SqlDataAdapter(sql_findofname, conn);
adapter.SelectCommand.Parameters.Add(p);
adapter.Fill(ds);
}
return ds;
}
本来这样是很正常的
现在我想加一个异常处理的机制.
public DataSet FindOfName(EmployeesAttribute employees)
{
try
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connstr))
{
SqlParameter p = new SqlParameter("@emp_name", SqlDbType.VarChar);
p.Value = "%" + employees.Emp_name + "%";
SqlDataAdapter adapter = new SqlDataAdapter(sql_findofname, conn);
adapter.SelectCommand.Parameters.Add(p);
adapter.Fill(ds);
}
return ds;
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
但是问题是提示:没有返回的值
我又想加个finally{return ds}.又提示"控制不能离开finall子句主体"
请问改怎么处理?