Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2009, 06:42 PM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HOW do you create a Login screen Using C#2008 textboxes to verify SQL SERVER DATA

Please assist, im new to C# and i want to create a login screen that inputs a username and password into texboxes and verify's it with the sql server database columns.
 
Old December 22nd, 2010, 11:40 AM
Registered User
 
Join Date: Dec 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Its very easy.

Create a Form.Place two label and two textbox.
now place a button from toolbox.Name it Login.

open properties window of texboxes (right click-->properties).Then in (NAME) property name its as txtUName and txtPwd.

double click button login.A code behind file opens with button click event trigerred.

Add in namespace:
using System.Data.SQlClient;

now in void button_Click(Object sender,EventArgs e)
{
if (txtUName.Text == "" || txtPwd.Text == "" )
{
MessageBox.Show("Please Fill All The Details", "Aarniko Finance");
txtUName.Focus();
}
else
{

sqlconnection cn=new sqlconnection("Server:yourcompuetname;Uid:sa;Pwd:e ntersqlpwd;Database:urlogintablename");
string chekcUN = "Select * from SysUser where UserName='"+txtUName.Text+"'";
SqlCommand cmd = new SqlCommand(chekcUN, cn);
SqlDataReader drd = cmd.ExecuteReader();

if(drd.HasRows)
{
while(drd.Read())
{
if (drd["Password"].ToString() == txtPwd.Text)
{
GlobalConnecton.UserId = txtUName.Text;
GlobalConnecton.Pwd = txtPwd.Text;
GlobalConnecton.UType = drd["UserType"].ToString();

this.Close();
ThreadStart ts = new ThreadStart(MainForm);
Thread td = new Thread(ts);
td.Start();
}
else
{
MessageBox.Show("Invalid User or wrong Password", "Aarniko Finance");
txtUName.ResetText();
txtPwd.ResetText();
txtUName.Focus();
}
}

}
else
{
MessageBox.Show("Invalid User or wrong Password", "Aarniko Finance");
txtUName.ResetText();
txtPwd.ResetText();
txtUName.Focus();

}
drd.Close();
}
}
 
Old April 6th, 2011, 07:38 AM
Authorized User
 
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

Whether you are developing the application for Web or Windows? If it is Web you can use the login control and the membership providers. If it is windows application just create a form and place required controls and send the data to the SQL Server and validate it against the table rows and return success or failure and based on this provide the message too...
__________________
Thanks in advance.

Regards,

Senthil Kumar M.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2008 XML speedlearner SQL Language 1 March 22nd, 2009 12:32 PM
Installing SQL Server 2008 Express Edition with Tools Kevin7777 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 March 8th, 2009 05:14 AM
SQL 2008 will not run on Windows 2008? dkrus Book: Professional Microsoft SQL Server 2008 Administration ISBN: 978-0-470-24796-9 1 February 23rd, 2009 12:34 PM
Article: Script Task (.NET) in SQL Server 2008 Integration Services (SSIS) jminatel BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 0 February 4th, 2009 12:52 AM
Using Windows Login to Verify User Access dasschmidthaus Pro VB.NET 2002/2003 14 February 1st, 2005 03:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.