Member Avatar for Rraeyinde

Hi guys. This is a cry for help from a desperate student!!! I don't expect you to do this for me I just need my mistake to be pointed out to me.

I'm creating a c# application which acts as a learning program to be used by teachers and learners. The teachers use it for their admin tasks and the learners use it for practising maths excercises. But before they can get to that they need to login to open the appropriate task window.

I have created two tabkes in Access one for teachers one for learners. The tables both contain the columns LogID, Name, Surname, Password, Class. The login form I've created requests the logId AND the password. and there is a combobox were the user can select whether they are a teacher or a learner.

what I want to do is ,when the Log in button is clicked, if the teacher option is selected in the combobox I want the program to check if the logid and password is in the same row in the teacherlog table in my database. and the same for the appropriate table if learner is selected in the combobox.

if the logid and password does exist then I want the next form to be opened for the user. If the user is a teacher the Teachers administration form should be opened, and if the user is a learner the learners task form should be opened.

NB. I have to use Visual Studio 2005, I must program in C#, I have to use ADO.net

Also please note that I am new to any form of programming language, C# being the first language I have learnt, so I am well aware that my mistake or rather problem is probably something that is simple for an experienced programmer. THANK YOU in advance for any help that is offered, it is really going to be appreciated. :)

the code that I am going to include shows no errors but it won't open the next form once I click the log in button.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace MathsNumeracy
{
    public partial class LogIn : Form
    {
        private string sConnection;
        private OleDbConnection dbConn;
        private OleDbCommand dbCmd;
        private Learner1 aLearner;
        private Teacher1 aTeacher;
        private OleDbDataReader dbReader;
        private string sql;


        public LogIn()
        {
            InitializeComponent();
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            Form1 start = new Form1();
            this.Hide();
            start.ShowDialog();
        }

        private void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                sConnection = "Provider = Microsoft.Jet.OLEDB.4.0;" +
                                    "DataSource = MathsNumeracy.mdb";
                dbConn = new OleDbConnection(sConnection);
                dbConn.Open();

                if (cmbStatus.Text.ToString() == "Teacher")
                {
                    sql = "Select LogID, Password From TeacherLog;";
                    dbCmd = new OleDbCommand();
                    dbCmd.CommandText = sql;
                    dbCmd.Connection = dbConn;

                    dbReader = dbCmd.ExecuteReader();

                    while (dbReader.Read())
                    {
                        aTeacher = new Teacher1(dbReader["LogID"].ToString(),dbReader["Name"].ToString(),dbReader["Surname"].ToString(), dbReader["Password"].ToString(), dbReader["Class"].ToString());
                        if ((dbReader["LogID"].ToString() == txtLogID.Text) && (dbReader["Password"].ToString() == txtPassword.Text))
                        {
                            TeacherAdmin tAdmin = new TeacherAdmin();
                            this.Hide();
                            tAdmin.ShowDialog();
                            this.Show();
                        }

                    }

                    
                }
                else
                    if (cmbStatus.Text.ToString() == "Learner")
                    {
                        sql = "Select * From LearnerLog;";
                        dbCmd = new OleDbCommand();
                        dbCmd.CommandText = sql;
                        dbCmd.Connection = dbConn;

                        dbReader = dbCmd.ExecuteReader();

                        while (dbReader.Read())
                        {
                            aLearner = new Learner1(dbReader["LogID"].ToString(), dbReader["Name"].ToString(), dbReader["Surname"].ToString(), dbReader["Password"].ToString(), dbReader["Class"].ToString());
                        
                            if ((dbReader["LogID"].ToString() == txtLogID.Text) && (dbReader["Password"].ToString() == txtPassword.Text))
                            {
                                LearnerTasks lTasks = new LearnerTasks();
                                this.Hide();
                                lTasks.ShowDialog();
                                this.Show();
                            }
                        }

                        
                    }
                dbReader.Close();
                dbConn.Close();
            }
            catch(System.Exception exc)
            {
                this.lblError.Text = exc.Message;
            }
        }

        
    }
}

ANY HELP WILL BE APPRECIATED ESPECIALLY SINCE I HAVE A DEADLINE FAST APPROACHING AND I STILL NEED TO FINISH MY OTHER CODING.

Then I would suggest you use the debug and step through your code, as it implies its not reaching the stage where it would show the dialogs you're expecting.

It would be easier to see in debug mode as to why it doesnt work as it will show you the values of everything

first i think its a bad idea using try catchs while you were learning... let the errors blow your program... :))

comment the unsuspected or unnecessary code...

check your code line by line as you are a debugger... Check all possible ways...

if you are sure the code is right that shows the form then you have problem with if statements...

debugging is always the key...

p.s.: i'm not a windows programmer... but i think you can try show the form first... then later close (or hide) the opener form...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.