try
{
..
}
catch(Exception ex)
{
  throw new Exception(ex.Message);
}在调用这个方法的函数中,也用try来捕捉。或者定义一个错误信息的只读属性,把错误信息保存在这个属性里,调用后检查这个属性就可以了。

解决方案 »

  1.   

    编译还是通不过,说不是所有代码路径都返回值。
    完整代码如下
    using System;
    using System.Data;
    using System.Data.SqlClient;namespace MyDb {
    public class DataBase {
    public string ConnectionString;
    private SqlConnection myConn;
    private SqlCommand myCmd;
    //...
    public SqlDataReader SelectSql(string strSelect){
    try{
      SqlConnection myConn=new SqlConnection(ConnectionString);
      SqlCommand myCmd=new SqlCommand(strSelect,myConn);
      myCmd.Connection.Open();
      return myCmd.ExecuteReader();
      myCmd.Connection.Close();
    }catch(SqlException ex){
    throw new Exception(ex.Message);
    }}
    //...
    public bool ExecuteNonQuery(string strQuery){
    try {
      SqlConnection myConn=new SqlConnection(ConnectionString);
      SqlCommand myCmd=new SqlCommand(strQuery,myConn);
      myCmd.Connection.Open();
      myCmd.ExecuteNonQuery();
      myCmd.Connection.Close();    
    }catch (SqlException ex) {
    throw new Exception(ex.Message);
    }
    }
    //...
    }
    }
      

  2.   

    你在try这一块就没有返回值嘛。
    在myCmd.Connection.Close(); 的后面加上:
     return true;