GetPicture publicoverride Picture GetPicture(int postID, int userID) { // 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; //30 //表示E欣欣4的相片的记录(不包括相片图片) myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = userID; //2105 //不是数据库User的那个GUID的UserID myCommand.Parameters.Add("@TrackViews", SqlDbType.Bit).Value =false; //false myCommand.Parameters.Add(this.SettingsIDParameter()); // Execute the command myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(); if (!dr.Read()) //此function的目的在于获取指定相片的记录,如果获取不成功,证明没有该相片,因此返回错误 { dr.Close(); myConnection.Close(); // we did not get back a post thrownew CSException(CSExceptionType.PostNotFound, postID.ToString()); } Picture p = PopulatePictureFromIDataReader(dr); //如果获取指定相片的记录正常,那么根据记录获取一个Picture类型的自定义对象变量 dr.Close(); myConnection.Close(); // we have a post to work with return p; } }