Click here to Skip to main content
16,017,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyClassLibrary
{
    class clsInvoiceNameCollection
    {
        //this function is used to populate the invoice class
        Int32 DisplayInvoice()
        {
            //create an instance of the invoice class
            clsInvoice Invoice = new clsInvoice();
            //var to store the invoice no primary key 
            string InvoiceNo;
            //var to store the name of the invoice 
            string InvoiceName;
            //var to store the index for the loop
            Int32 Index = 0;
            //while the index is less that the number of records to process
            while (Index < Invoices.Count)
            {
                //get the invoice number from the database
                InvoiceNo = Convert.ToString(Invoices.AllInvoices[Index].InvoiceNo);
                //get the invoice name from the database 
                Invoice = Invoice.AllInvoices[Index].Invoice;
                //set up the new row to be added to the list
                ListItem NewInvoice = new ListItem(Invoice, InvoiceNo);
                //add the new row to the list
                ddlInvoice.Items.Add(NewInvoice);
                //increment the index to the next record
                Index++;
            }
            //return the number of records found
            return Invoice.Count;
        }
    }
}

Errors are:
Error	1	The name 'Invoices' does not exist in the current context	
Error	2	The name 'Invoices' does not exist in the current context	
Error	3	'MyClassLibrary.clsInvoice' does not contain a definition for 'AllInvoices' and no extension method 'AllInvoices' accepting a first argument of type 'MyClassLibrary.clsInvoice' could be found (are you missing a using directive or an assembly reference?)	
Error	4	The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)	
Error	5	The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)
Error	6	The name 'ddlInvoice' does not exist in the current context	
Error	7	Cannot convert method group 'Count' to non-delegate type 'int'. Did you intend to invoke the method?	


What is underlined:
C#
- while (Index < Invoices.Count) 'Invoices' part
- InvoiceNo = Convert.ToString(Invoices.AllInvoices[Index].InvoiceNo); 'Invoices' part
- Invoice = Invoice.AllInvoices[Index].Invoice; 'AllInvoices' part
- ListItem NewInvoice = new ListItem(Invoice, InvoiceNo); Both the 'ListItem' parts
- ddlInvoice.Items.Add(NewInvoice); The 'ddlInvoice' part
- return Invoice.Count; 'Invoice.Count' part


}


What I have tried:

Need assistance!!!! I am a beginner in programming so please help me. Thanks in advance. :)
Posted
Updated 1-Apr-16 1:25am
v2
Comments
Karthik_Mahalingam 1-Apr-16 7:22am    
you will have to define Invoices,
you have copied the code from somewhere, make sure you have copied all the references.
F-ES Sitecore 1-Apr-16 7:24am    
What is "Invoices"? You are using it without defining it anywhere.

You can't learn how to program by just throwing some code together then asking a forum why it doesn't compile, you need to actually understand what you're doing. If I was you I'd get a book on c# and go through it to get a grounding in the basics.

1 solution

It's fairly obvious - you haven't declared anything called "Invoices".
It's possible that you have got a collection somewhere else in your program called Invoices, but it cannot be referenced here.
You need to know about Scope[^]

Once you've worked out how to get over the first problem (e.g. you could pass Invoices as a parameter to the DisplayInvoice method, or actually have it as a property of the class clsInvoiceNameCollection), you will find that most of the other errors will just "disappear". Always look at the first listed error when you get compile errors, fix it, then retry the compile.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900