blog

Home / DeveloperSection / Blogs / Login_Form

Login_Form

Arushraj Raj 4396 18-Jul-2011
try
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = "Data Source=ARUSHRAJ-PC;Initial Catalog=sample;User ID=sa;Password=niit";
                con.Open();
                SqlCommand cmd = new SqlCommand("Select * From Login_Details Where UserType=@ut AND UserName=@nm AND Password = @ps", con);
                cmd.Parameters.Add("@ut", SqlDbType.VarChar, 50);
                cmd.Parameters.Add("@nm", SqlDbType.VarChar, 50);
                cmd.Parameters.Add("@ps", SqlDbType.VarChar, 50);
                cmd.Parameters["@ut"].Value = comboBox1.Text;
                cmd.Parameters["@nm"].Value = textBox1.Text;
                cmd.Parameters["@ps"].Value = textBox2.Text;
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    DialogResult rd = MessageBox.Show("Login Succesfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (rd == DialogResult.OK)
                    {
                        if (dr.Read())
                        {
                            label6.Text = dr[1].ToString();
                            label8.Text = dr[0].ToString();
                        }
                    }
                }
                else
                {
                    ctr = ctr + 1;
                    if (ctr < 3)
                    {
                        DialogResult dr1 = MessageBox.Show("You have enter wrong Username or Password. If you are forget your Password or UserName ", "Warning", MessageBoxButtons.RetryCancel,MessageBoxIcon.Warning);
                        if (dr1 == DialogResult.Cancel)
                        {
                            Application.Exit();
                        }
                        linkLabel6.Show();
                        textBox1.Text = "";
                        textBox2.Text = "";
                        textBox1.Focus();
                    }
                    else
                    {
                        MessageBox.Show("You can not access this appliction.Because of you enter 3 times wrong Username or Password", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        textBox1.Text = "";
                        textBox2.Text = "";
                        Application.Exit();
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Updated 18-Sep-2014

Leave Comment

Comments

Liked By