GetPost /**////<summary> /// Get basic information about a single post. This method returns an instance of the Post class, /// which contains less information than the PostDeails class, which is what is returned by the /// GetPostDetails method. ///</summary> ///<param name="PostID">The ID of the post whose information we are interested in.</param> ///<returns>An instance of the Post class.</returns> ///<remarks>If a PostID is passed in that is NOT found in the database, a PostNotFoundException /// exception is thrown.</remarks> publicoverride ForumPost GetPost(int postID, int userID, bool trackViews) { // Create Instance of Connection and Command Object using( SqlConnection myConnection = GetSqlConnection() ) { SqlCommand myCommand =new SqlCommand(databaseOwner +".cs_forums_Post", myConnection); // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC myCommand.Parameters.Add("@PostID", SqlDbType.Int).Value = postID; myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = userID; myCommand.Parameters.Add("@TrackViews", SqlDbType.Bit).Value = trackViews; myCommand.Parameters.Add(this.SettingsIDParameter()); // Execute the command myConnection.Open(); ForumPost p =null; using(SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection)) { if (!dr.Read()) { dr.Close(); myConnection.Close(); // we did not get back a post thrownew CSException(CSExceptionType.PostNotFound, postID.ToString()); } p = PopulatePostFromIDataReader(dr); dr.Close(); } myConnection.Close(); // we have a post to work with return p; } }
posted on
2005-10-18 14:36Konimeter
阅读(238)
评论(0)
收藏举报