Solved

Authenticate Users (Login Page)

Posted on 2004-08-08
3
228 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 35 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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