?
Solved

Error associated with delegate

Posted on 2005-02-24
6
Medium Priority
?
358 Views
Last Modified: 2008-02-01
I am trying to use a delegate which should pass a handle of a method (GenerateLinkCollectionFromReader) in a child class to the parent class however when I try to comple I get the error below and I can't figure out why.  Any help would be appreciated!

============== ERROR =================

c:\inetpub\wwwroot\DAL\DataAccessLayer.cs(132):
Inconsistent accessibility: parameter type 'DataAccessLayer.SqlDataAccessLayer.GenerateCollectionFromReader'
is less accessible than method
'DataAccessLayer.SqlDataAccessLayer.ExecuteReaderCmd(System.Data.SqlClient.SqlCommand, DataAccessLayer.SqlDataAccessLayer.GenerateCollectionFromReader)'

============== CODE SNIPS =============

namespace DataAccessLayer
{
      delegate CollectionBase GenerateCollectionFromReader(IDataReader returnData);

      public abstract class SqlDataAccessLayer
      {
            public SqlDataAccessLayer()
            {
            }


(132)-->            protected CollectionBase ExecuteReaderCmd(SqlCommand sqlCmd, GenerateCollectionFromReader gcfr)
            {
                  if (strConnectionString == String.Empty)
                  {
                        throw new ArgumentOutOfRangeException("strConnectionString");
                  }
                  if (sqlCmd == null)
                  {
                        throw new ArgumentNullException("sqlCmd");
                  }

                  SqlConnection cn = new SqlConnection(this.strConnectionString);

                  try
                  {
                        sqlCmd.Connection = cn;
                        cn.Open();
                        CollectionBase temp = gcfr(sqlCmd.ExecuteReader());
                        return temp;
                  }
                  finally
                  {
                        cn.Dispose();
                  }

            } // End ExecuteReaderCmd
}



namespace DataAccessLayer
{

      public class LinkTrackerDataAccessLayer : SqlDataAccessLayer

      public LinkCollection GetLinkByID(int LinkID)
      {
            SqlCommand sqlCmd = new SqlCommand();
            AddParamToSQLCmd(sqlCmd, "@link_id", SqlDbType.Int, 0, ParameterDirection.Input, LinkID);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_LINK_GETLINKBYID);
                              
            GenerateCollectionFromReader sqlData = new GenerateCollectionFromReader(GenerateLinkCollectionFromReader);
           
            LinkCollection stsCollection = (LinkCollection)ExecuteReaderCmd(sqlCmd, sqlData);
            return stsCollection;
      }
      
      private CollectionBase GenerateLinkCollectionFromReader(IDataReader returnData)
      {
            // Create new link collection.
            LinkCollection mlsCollection = new LinkCollection();

            //
            while(returnData.Read())
            {
                  Link newLink = new Link(int.Parse(returnData("link_id")),
                  returnData("title").ToString(),
                  returnData("destinationURL").ToString(),
                  returnData("descript").ToString(),
                  (DateTime)returnData("dateCreated"));
                  mlsCollection.Add(newLink);
            }
            // Return Collction
            return mlsCollection;
      }      // End GenerateLinkCollectionFromReader
           } // End LinkTrackerDataAccessLayer
} // End Namespace
0
Comment
Question by:g9support
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 13399014
Try changing:
   protected CollectionBase ExecuteReaderCmd
to:
   public CollectionBase ExecuteReaderCmd
0
 

Author Comment

by:g9support
ID: 13404416
Yeah, I tried that and I still get the "blue squiggly" line with the same error.
hhmmmm....
0
 

Author Comment

by:g9support
ID: 13404504
Ok, I figured it out and I'm posting it here just in case someone else has the same problem.

The delegate delcaration was outside of the class scope. I moved the delegate declaration into the class and added  the "protected" modifier to the declaration.

BLAMMO! The problem was solved.

(now, onto more debugging... how fun)
0
 

Author Comment

by:g9support
ID: 13592365
I figured out the problem my self and posted it above. How do I close a question if i figured it out myself?
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13628434
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question