public void ReadMyData(string myConnString) { string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders"; SqlConnection myConnection = new SqlConnection(myConnString); SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection); myConnection.Open(); SqlDataReader myReader; myReader = myCommand.ExecuteReader(); // Always call Read before accessing data. while (myReader.Read()) { Response.Write(myReader.GetInt32(0) + ", " + myReader.GetString(1)); } // always call Close when done reading. myReader.Close(); // Close the connection when done with it. myConnection.Close();