[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Authenticate Users (Login Page)

Posted on 2004-08-08
3
Medium Priority
?
233 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 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