?
Solved

Authenticate Users (Login Page)

Posted on 2004-08-08
3
Medium Priority
?
230 Views
Last Modified: 2010-04-15
Hi guys,
I have two forms, form1 and form2. I also have this login page written in C# in form1. I'm trying to authenticate users through SQL database, if authenticated they will login to form 2, if not an error message should pop up and not allow form2 to open. Also after authentication is sucessfull, form1 should close and form2 should stay open. First concentrate on authenticating users and allowwing form2 to open. Afterwards form1 should close automatically if users are authenticated.Here's the code:

da.Open();

SqlCommand thisCommand = da.CreateCommand();
String sQuery = "SELECT count(*) FROM License WHERE Name = '"+ textBox1.Text +"' AND LicenseID = '"+ textBox2.Text +"'"

SqlCommand cmd = new SqlCommand(sQuery, da);
SqlDataReader dr = cmd.ExecuteReader();
Form2 frm = new Form2();
//if (dr.["License"].Rows.Count == 0)
//MessageBox.Show("Incorrect UserName and/or ID, Try again!");
da.Close();
frm.Show();

I'm stuck on authentication and closing the form1, can someone direct me where i have gone wrong.
Thanks, Les
0
Comment
Question by:lesmydad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:jkrill
ID: 11746998
I believe this MSDN article describes how to accomplish what you are looking for:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;301240
0
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 140 total points
ID: 11749948
Replace Code as

da.Open();
SqlCommand thisCommand = da.CreateCommand();
String sQuery = "SELECT count(*) FROM License WHERE Name = '"+ textBox1.Text +"' AND LicenseID = '"+ textBox2.Text +"'"
SqlCommand cmd = new SqlCommand(sQuery, da);
SqlDataReader dr = cmd.ExecuteReader();
                  if(dr.Read())
                  {
                        dr.Close();
                                                                da.Close();
                        this.Visible = false;
                        Form2 frm = new Form2();
                        frm.ShowDialog();
                        this.Close();
                  }
                  else
                  {
                        dr.Close();
                                                                da.Close();
                        MessageBox.Show("Incorrect UserName and/or ID, Try again!");
                  }


Cheers,
S Sansanwal
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11751032
S Sansanwal,
The above script does not authenticate users, but it closes form1 and opens form2. Any this was my fault, thw sQuery should had this command
SELECT Name, LicenseID FROM License     instead of

SELECT count(*) FROM License
This authticates users, then opens form2 and closes form1. If users are not authenticated the error message is shown.
Any way thanks for your help.
Les
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question