myConnection.Close();
myConnection 是你打开的数据库连接。

解决方案 »

  1.   

    myReader.Close();
    myConnection.Close();看msdn:备注
    如果想通过使用 OleDbDataReader 来将关联的 OleDbConnection 用于任何其他目的,则必须显式调用 Close 方法。示例
    [Visual Basic, C#] 以下示例创建一个 OleDbConnection、一个 OleDbCommand 和一个 OleDbDataReader。该示例读取全部数据,并将其写到控制台。最后,该示例先关闭 OleDbDataReader,再关闭 OleDbConnection。[Visual Basic] 
    Public Sub ReadMyData(myConnString As String)
        Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
        Dim myConnection As New OleDbConnection(myConnString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()
        ' Always call Read before accessing data.
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
               + myReader.GetString(1))
        End While
        ' always call Close when done reading.
        myReader.Close()
        ' Close the connection when done with it.
        myConnection.Close()
    End Sub[C#] 
    public void ReadMyData(string myConnString) 
    {
       string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";
       OleDbConnection myConnection = new OleDbConnection(myConnString);
       OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);
       myConnection.Open();
       OleDbDataReader myReader;
       myReader = myCommand.ExecuteReader();
       // Always call Read before accessing data.
       while (myReader.Read()) {
          Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
       }
       // always call Close when done reading.
       myReader.Close();
       // Close the connection when done with it.
       myConnection.Close();
    }
      

  2.   

    可为什么当我关闭后再用command打开一个连接时总是提示要我先关闭datareader所用的连接?
      

  3.   

    把另一个command的事件写到另一个函数中,然后在上一个函数中调中就OK了
      

  4.   

    在执行 Command.ExecuteReader()时指定 CommandBehavior.CloseConnection即这样调用:Command.ExecuteReader( CommandBehavior.CloseConnection ) 这样你的
    DataReader.Close()的同时你的 connection 也会close