Returning true/false in a boolean function
-
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; } }
-
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; } }
You have to fill the DataSet before you read from it.
adapter.Fill(ds6, "Teacher");
-
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; } }
You are just creating an adapter and a dataset. You have fill the dataset using the adapter.
adapter.Fill(ds6);
or
adapter.Fill(ds6, "");