Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click_1(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");
    con.Open();
    DataSet ds = new DataSet();
    if (textBox1.Text == "@UserName" && textBox2.Text == "@Password")
    {
        Administrator_Home ah = new Administrator_Home();
        ah.Show();
    }
    else
        MessageBox.Show("invalid username or password");
}
Posted
Updated 11-Mar-14 7:01am
v2
Comments
Richard MacCutchan 11-Mar-14 13:03pm    
Credentials are used to login to the database and are validated internally. Your code just needs to check whether it succeeds or not.

Hai

Try this


C#
   private void btnOk_Click(object sender, EventArgs e)
        {
            
        SqlConnection connect = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");
DataTable dt1 = new DataTable();
string strcmd1 = "";
SqlDataAdapter cmd1 = new SqlbDataAdapter;
                      connect.Open();
           strcmd1  = ("SELECT UserName, PassWord FROM Admin WHERE UserName='" & Textbox1.Text.Trim() & "' and Password='" & Textbox1.Text.Trim() & "'");
 

cmd1 = new SqlDataAdapter(new SqlCommand(strcmd1));
cmd1.SelectCommand.Connection = connect;
 
cmd1.Fill(dt1)
if ((dt1.Rows.Count > 0)) {
	 Administrator_Home ah = new Administrator_Home();
        ah.Show();
} else {
MessageBox.Show("invalid username or password");
}
        }
 
    }
}
 
Share this answer
 
v2
Comments
Abhinav Chaudhary 12-Mar-14 6:20am    
Thanks Sir,it was really helpful...its working!!!
Aravindba 12-Mar-14 6:22am    
ok,no problem,u r welcome...
There are tons of examples on CP Knowledge Base[^] and via Google[^]
 
Share this answer
 
its very simple friend just use the sql qry like select * from tbl where username ='' and pwd =''

if u return result then user is available else user s nt available
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900