string Conn="Database=snpsolution; user id=sa; password=chinu111";
int Flag = 0;
SqlConnection con = new SqlConnection("Database=snpsolution; user id=sa; password=chinu111");
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(Conn);
conn.Open();
string strLoginCheck = "select * from Useraccount";
SqlCommand cmdLoginCheck = new SqlCommand(strLoginCheck, conn);
SqlDataReader dr = cmdLoginCheck.ExecuteReader();
while (dr.Read())
{
if (dr["Userid"].ToString() ==txtusername.Text)
{
MessageBox.Show("User is Already Exists.", "Snp Solution... ", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
Flag = 1;
}
}
if (txtusername. Text.Equals("") || txtPassword. Text.Equals("") || textBox1. Text.Equals(""))
{
MessageBox.Show("Fill the Information.", " Snp Solution... ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtPassword.Text !=textBox1. Text)
{
MessageBox.Show("Password is Not Match.", "Snp Solution... ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtPassword. Text ==textBox1. Text && Flag == 0)
{
string str = "insert into Useraccount values('" + txtusername.Text + "','" + txtPassword.Text + "')";
SqlCommand cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("User Registerd..... ", "Snp Solution... ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Flag = 0;
dr.Close();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Snp Solution...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}