Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Í build a class file.

But a little problem.

 

I like it that the class has a function that returns something (an integer in this case) to the main file.

 

So this is the incorrect part of my class:

 

       public void aantal_klanten()
       {
           int hoeveelheid;
           try
           {
               OleDbConnection Connection = new OleDbConnection();
               Connection = dbase(Connection);
               // Create an OleDb command, 
               OleDbCommand myCommand = new OleDbCommand("count (*) from Bedrijven", Connection);
               Connection.Open();
               OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
               while (myReader.Read())
               {
                   hoeveelheid = Convert.ToInt32(myReader.GetString(0));
               }
               Connection.Close();
               return hoeveelheid;
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex.Message);
           }
       }

 

It shoud not be a void i guess.. but i forgot what it must be..

Inside the class i use this for example, that works:

static OleDbConnection dbase(OleDbConnection Connection)

 

The class is named: Class_customers:

 

Class_customers klant = new Class_customers();

 

So i like to use this kind of code:

 

int counting;

counting = klant.aantal_klanten();

 

Whats the correct syntax ?

 

Gr. Jelmer

Posted

I'll changed it to this, i think this is good.. but i'll get the following error;

 

.aantalklanten()': not all code paths return a value

 

Code:

 

        public int aantalklanten()
       {
           int hoeveelheid;
           try
           {
               OleDbConnection Connection = new OleDbConnection();
               Connection = dbase(Connection);
               // Create an OleDb command, 
               OleDbCommand myCommand = new OleDbCommand("count (*) from Bedrijven", Connection);
               Connection.Open();
               OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
               while (myReader.Read())
               {
                   hoeveelheid = Convert.ToInt32(myReader.GetString(0));
               }
               Connection.Close();
               return 10;
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex.Message);
           }
       }

  • *Experts*
Posted

And I assume you want to "return hoeveelheid;" instead of "return 10;"

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...