如果返回Connection的话,command复用一定会很多 。
如果返回Command,Connection怕没有办法关闭,
DBHelper里有好几个方法,其中Connection是在一个方法里面的,有什么办法可以既返回Command 而且还可以手动关闭Connection的呀?

解决方案 »

  1.   

    本来就是很简单的事情!比如下面:
    try
        {
            command.Connection.Open();
            command.ExecuteNonQuery();
        }
        finally
        {
            if ((command != null) && (command.Connection != null) && 
                (ConnectionState.Closed != command.Connection.State))
            {
                command.Connection.Close();
            }
            command.Dispose();
        }
      

  2.   

    自己写个方法 手动关闭private Sqlconnection conn;
    public void Close()
    {
      if(conn.state==ConnectionState.open)
      {
       conn.close();
      }
    }