| | |
How do I create a login form to open the next appropriate form?
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
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.
ANY HELP WILL BE APPRECIATED ESPECIALLY SINCE I HAVE A DEADLINE FAST APPROACHING AND I STILL NEED TO FINISH MY OTHER CODING.
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.
C# Syntax (Toggle Plain Text)
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.
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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...
)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...
![]() |
Similar Threads
- Simple ASP.Net Login Page using C# (C#)
- Open and Close Winform (C#)
- Need help with Login/Database (ASP)
- login Form using Access database (VB.NET)
- appear in other form (Visual Basic 4 / 5 / 6)
- Creating a Login Page (ASP)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: AutoPatch system Problem
- Next Thread: to be install once
Views: 1419 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






