hi every one,
i make a application in C# visual studio that store username and passwords or students now i want to make a login form in c#.

it is window form based application (GUI) not Cmd base:-
my main objective is that first my application check that whether username exist or not and if it exit then compare it and show the form of student area ..
plz help me it's not my assignment i want to learn it the database is Microsoft Access
i already able to store data in database the main problem is how can i retrieve data and compare it with the value that i got from user

Recommended Answers

All 3 Replies

>how can i retrieve data and compare it with the value that i got from user

Form a select query.

string query="select [username],[password] from [tableName] where [username]=@username and [password]=@password";

Execute query using ExecuteReader method.

cn=new OleDbConnection("conn_string_here");
 cmd=new OleDbCommand();
 cmd.CommandText=query;
 cmd.Connection=cn;
 
 cmd.Parameters.AddWithValue("@username",UserName.Text);
 cmd.Parameters.AddWithValue("@password",PassWord.Text);
 
 cn.Open();
 OleDbDataReader dr=cmd.ExecureReader();
 string user=string.Empty;
 string pass=string.Empty;

 if(dr.Read()) {
    user=dr.GetString(0);
    pass=dr.GetString(1);
 }
 
 dr.Close();
 cn.Close();

 if(user==UserName.Text && pass==PassWord.Text) {
    ///Success
  }
 else
  {
    ///Fails
  }

Error 1 The name 'cn' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 43 13 StudentLogin
Error 2 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 44 13 StudentLogin
Error 3 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 45 13 StudentLogin
Error 4 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 46 13 StudentLogin
Error 5 The name 'cn' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 46 30 StudentLogin
Error 6 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 48 13 StudentLogin
Error 7 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 49 13 StudentLogin
Error 8 The name 'cn' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 51 13 StudentLogin
Error 9 The name 'cmd' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 52 34 StudentLogin
Error 10 The name 'cn' does not exist in the current context C:\Documents and Settings\Wasif\My Documents\Visual Studio 2008\Projects\StudentLogin\StudentLogin\loginForm.cs 63 13 StudentLogin

plz help me i am using GUI not CMD applciation

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.