Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
//this function is used to populate the invoice class
       Int32 DisplayInvoices()
       {
           //create an instance of the county class
           clsInvoice Invoice = new clsInvoice();
           //var to store the invoice no primary key
           string InvoiceNo;
           //var to store the name of the invoice
           string Invoice;
           //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 = Invoices.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 Invoices.Count;

       }


What I have tried:

I have tried adding this code to the clsinvoicecollection class but i am getting errors.
Posted
Updated 31-Mar-16 0:15am
Comments
Patrice T 31-Mar-16 6:09am    
And you plan to tell us which errors and where ?
Karthik_Mahalingam 31-Mar-16 6:40am    
what is the error message?
Gomez786 31-Mar-16 6:53am    
errors codes are:
-Int32 DisplayInvoices() just the 'Int32' part
-clsInvoice Invoice = new clsInvoice(); just the 'clsInvoice'(); part
-InvoiceNo = Convert.ToString(Invoice.AllInvoices[Index].InvoiceNo); just the '[Index]. part
-Invoice = Invoice.AllInvoices[Index].Invoice; just the '[Index].' part
-ListItem NewInvoice = new ListItem(Invoice, InvoiceNo); just the 'ListItem' part before (Invoice, etc.
-return Invoice.Count; just the 'return' part
Gomez786 31-Mar-16 7:04am    
Error 1 A namespace cannot directly contain members such as fields or methods
Error 2 Expected class, delegate, enum, interface, or struct
Error 3 Expected class, delegate, enum, interface, or struct
Error 4 Expected class, delegate, enum, interface, or struct
Error 5 Expected class, delegate, enum, interface, or struct
Error 6 A namespace cannot directly contain members such as fields or methods
Error 7 Type or namespace definition, or end-of-file expected
Gomez786 31-Mar-16 7:03am    
Error 1 A namespace cannot directly contain members such as fields or methods
Error 2 Expected class, delegate, enum, interface, or struct
Error 3 Expected class, delegate, enum, interface, or struct
Error 4 Expected class, delegate, enum, interface, or struct
Error 5 Expected class, delegate, enum, interface, or struct
Error 6 A namespace cannot directly contain members such as fields or methods
Error 7 Type or namespace definition, or end-of-file expected

1 solution

You don't need that first new clsInvoice for starters.

Second, you're masking that variable (clsInvoice Invoice) with string Invoice.

Without seeing your erorr I cannot be sure, but I'm guessing the line the program fails is
C#
Invoice = Invoices.AllInvoices[Index].Invoice 

and you get some kind of type mismatch error.

Just a guess...but if it is correct one, please accept this solution.
If it is not, update the question with more details.
 
Share this answer
 
Comments
Gomez786 31-Mar-16 6:18am    
thanks, can you please elaborate and remove the unneccesary lines of codes that are not needed so i may try it?
Gomez786 31-Mar-16 6:57am    
errors codes are:
-Int32 DisplayInvoices() just the 'Int32' part
-clsInvoice Invoice = new clsInvoice(); just the 'clsInvoice'(); part
-InvoiceNo = Convert.ToString(Invoice.AllInvoices[Index].InvoiceNo); just the '[Index]. part
-Invoice = Invoice.AllInvoices[Index].Invoice; just the '[Index].' part
-ListItem NewInvoice = new ListItem(Invoice, InvoiceNo); just the 'ListItem' part before (Invoice, etc.
-return Invoice.Count; just the 'return' part

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