Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Returning true/false in a boolean function

Returning true/false in a boolean function

Scheduled Pinned Locked Moved ASP.NET
sysadminquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WickedFooker
    wrote on last edited by
    #1

    I am trying to say if a teacher is already teaching 3 classes flag it by returning a true if so, or a false if not. I have it counting the rows (or so I thought), but it is saying the way I did it is not correct. That Tables[0] is invalid.

    private bool ValidateTeacher(string TeacherID, String Semester)
    {
    // Populate Room and add Please Select
    string path = Server.MapPath("eAcademy_DB.mdb");
    string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
    string commandText = "SELECT COUNT(*) FROM tblClass WHERE emp_ID=? and sem_Time=?";

        var ds6 = new DataSet();
    
        using (var connection = new OleDbConnection(connectionString))
        using (var command = new OleDbCommand(commandText, connection))
        {
            // OleDbCommand uses positional, rather than named, parameters.
            // The parameter name doesn't matter; only the position.
          
    
            var adapter = new OleDbDataAdapter(command);
            if (ds6.Tables\[0\].Rows.Count > 3)
            {
                return false;
            }
            else return true;
            
        }
    }
    
    J M 2 Replies Last reply
    0
    • W WickedFooker

      I am trying to say if a teacher is already teaching 3 classes flag it by returning a true if so, or a false if not. I have it counting the rows (or so I thought), but it is saying the way I did it is not correct. That Tables[0] is invalid.

      private bool ValidateTeacher(string TeacherID, String Semester)
      {
      // Populate Room and add Please Select
      string path = Server.MapPath("eAcademy_DB.mdb");
      string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
      string commandText = "SELECT COUNT(*) FROM tblClass WHERE emp_ID=? and sem_Time=?";

          var ds6 = new DataSet();
      
          using (var connection = new OleDbConnection(connectionString))
          using (var command = new OleDbCommand(commandText, connection))
          {
              // OleDbCommand uses positional, rather than named, parameters.
              // The parameter name doesn't matter; only the position.
            
      
              var adapter = new OleDbDataAdapter(command);
              if (ds6.Tables\[0\].Rows.Count > 3)
              {
                  return false;
              }
              else return true;
              
          }
      }
      
      J Offline
      J Offline
      Joshua Omundson
      wrote on last edited by
      #2

      You have to fill the DataSet before you read from it.

      adapter.Fill(ds6, "Teacher");

      1 Reply Last reply
      0
      • W WickedFooker

        I am trying to say if a teacher is already teaching 3 classes flag it by returning a true if so, or a false if not. I have it counting the rows (or so I thought), but it is saying the way I did it is not correct. That Tables[0] is invalid.

        private bool ValidateTeacher(string TeacherID, String Semester)
        {
        // Populate Room and add Please Select
        string path = Server.MapPath("eAcademy_DB.mdb");
        string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
        string commandText = "SELECT COUNT(*) FROM tblClass WHERE emp_ID=? and sem_Time=?";

            var ds6 = new DataSet();
        
            using (var connection = new OleDbConnection(connectionString))
            using (var command = new OleDbCommand(commandText, connection))
            {
                // OleDbCommand uses positional, rather than named, parameters.
                // The parameter name doesn't matter; only the position.
              
        
                var adapter = new OleDbDataAdapter(command);
                if (ds6.Tables\[0\].Rows.Count > 3)
                {
                    return false;
                }
                else return true;
                
            }
        }
        
        M Offline
        M Offline
        Muhammed Yaseen
        wrote on last edited by
        #3

        You are just creating an adapter and a dataset. You have fill the dataset using the adapter.

        adapter.Fill(ds6);

        or

        adapter.Fill(ds6, "");

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups