Click here to Skip to main content
15,928,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: Checking If Form Is Loaded Pin
Jon G6-Oct-04 8:45
Jon G6-Oct-04 8:45 
GeneralRe: Checking If Form Is Loaded Pin
Brian Nottingham6-Oct-04 12:57
Brian Nottingham6-Oct-04 12:57 
GeneralMAPI programming by C# Pin
ppp0016-Oct-04 5:53
ppp0016-Oct-04 5:53 
GeneralRe: MAPI programming by C# Pin
Heath Stewart6-Oct-04 13:40
protectorHeath Stewart6-Oct-04 13:40 
GeneralKeyboard question Pin
Jose Vicente6-Oct-04 5:28
Jose Vicente6-Oct-04 5:28 
GeneralRe: Keyboard question Pin
Alex Korchemniy6-Oct-04 8:10
Alex Korchemniy6-Oct-04 8:10 
GeneralRe: Keyboard question Pin
Jose Vicente6-Oct-04 21:10
Jose Vicente6-Oct-04 21:10 
GeneralRecieving error: unhandled exception... Pin
Moochie56-Oct-04 5:12
Moochie56-Oct-04 5:12 
Topic cont'd... of type 'System.Data.Odbc.OdbcException' occurred in system.data.dll
Additional Information : System error

First of all hello, this is my first post, great site here, seems like their a lot of knowledgable people. Anyway I am just beginning to learn C#. I am creating a program for where I work for employees to login with a username and password and after successfully logging in they can clock in and clock out.

I am working on the login page first, known as form1 in my project. When the user clicks the "Login" button(known as button1) I would like it to load the next form where the user will be able to clock in and clock out. All the usernames and passwords are on a Access table. They will not be able to create their own but just use the preset ones. I want the program to check if what the user entered in as the username and password match whats on the table and if it does not, then it will display an error.

Here is a little snip of my code and I will point out which line the error points to:


public void button1_Click(object sender, System.EventArgs e) <br />
{ <br />
  OdbcDataReader myReader; <br />
  string myConnString = "DSN=MS Access  Database;DefaultDir=C:\\DOCUMENTS AND SETTINGS\\OWNER\\MY DOCUMENTS;DriverId=25;DBQ=C:\\DOCUMENTS AND SETTINGS\\OWNER\\MY DOCUMENTS\\login.mdb;MaxBufferSize=2048;FIL=MS Access;PageTimeout=5;UID=admin"; <br />
//string password; <br />
string mySelectQuery = "SELECT Username, Password FROM tblLogin WHERE Username = " + txtUserName.Text; <br />
OdbcConnection myConnection = new OdbcConnection(myConnString); <br />
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection); <br />
myConnection.Open(); <br />
[CODE]myReader = myCommand.ExecuteReader();[/CODE] <br />
while(myReader.IsDBNull(0)) <br />
{ <br />
   lblErrorUser.Visible=true; <br />
} 




The error points to the myReader = myCommand.ExecuteReader() line.
It does open the connection fine but when I click the Login button the error above comes up. If I comment in that line(using //) and the while loop, the program runs fine, well doesnt do what I want it to do but when I click the Login button it opens form2.

I believe it has something to do with the myReader variable. I have declared it as OdbcDataReader myReader where I have all my functions declared. I just noticed that their is a blue squiggly under the myReader where its declared.

Also, just want to mention that before this 'system error' I was recieving the following error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

and it was still pointing at the myReader = myCommand.ExecuteReader(); I did not change anything and all of a sudden I was recieving the system error. It still points at the myReader variable though.

Help is greatly appreciated. Thanks!
GeneralRe: Recieving error: unhandled exception... Pin
Heath Stewart6-Oct-04 13:36
protectorHeath Stewart6-Oct-04 13:36 
QuestionRecord install path? Pin
the last free name6-Oct-04 4:50
the last free name6-Oct-04 4:50 
AnswerRe: Record install path? Pin
Heath Stewart6-Oct-04 13:25
protectorHeath Stewart6-Oct-04 13:25 
GeneralPanel control in a DLL Pin
Reinier van de Wetering6-Oct-04 4:48
Reinier van de Wetering6-Oct-04 4:48 
GeneralRe: Panel control in a DLL Pin
Jon G6-Oct-04 5:06
Jon G6-Oct-04 5:06 
GeneralRe: Panel control in a DLL Pin
Reinier van de Wetering6-Oct-04 19:47
Reinier van de Wetering6-Oct-04 19:47 
Generaldisplaying nested tables Pin
njaromack6-Oct-04 4:34
njaromack6-Oct-04 4:34 
GeneralRe: displaying nested tables Pin
njaromack6-Oct-04 10:36
njaromack6-Oct-04 10:36 
GeneralRe: displaying nested tables Pin
Heath Stewart6-Oct-04 13:16
protectorHeath Stewart6-Oct-04 13:16 
GeneralChange windows service logon account and password using c# Pin
Subin KJ6-Oct-04 4:31
Subin KJ6-Oct-04 4:31 
GeneralRe: Change windows service logon account and password using c# Pin
Heath Stewart6-Oct-04 12:57
protectorHeath Stewart6-Oct-04 12:57 
GeneralLogin Pin
pat2708816-Oct-04 4:31
pat2708816-Oct-04 4:31 
GeneralRe: Login Pin
Heath Stewart6-Oct-04 12:34
protectorHeath Stewart6-Oct-04 12:34 
GeneralRe: Login Pin
pat2708817-Oct-04 7:38
pat2708817-Oct-04 7:38 
GeneralRe: Login Pin
pat2708817-Oct-04 7:43
pat2708817-Oct-04 7:43 
Generalsetting datagrid cursors Pin
ddelapasse6-Oct-04 4:01
ddelapasse6-Oct-04 4:01 
Question.NET OLAP control? Pin
jvbragt6-Oct-04 2:29
jvbragt6-Oct-04 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.