---
title: "Login_Form"  
description: "try                    SqlConnection con = new SqlConnection();                  con.ConnectionString = \"Data Source=ARUSHRAJ-PC;Initial Catalog=sampl"  
author: "Arushraj Raj"  
published: 2011-07-18  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/206/login_form  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 4 minutes  

---

# Login_Form

```
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);            }
```

---

Original Source: https://www.mindstick.com/blog/206/login_form

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
