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();
}
}
|