hi all,
i have few assistance in my code below.
i have developed by c# with windows application
my flow is :,
i have set three roles while login details
they are,
1.user
2.admin
3.others
these are all contains my three roles, i actually done this process but what happened my code means,
if i enter correct user name and password means its working fine but,
if i suppossed to type wrong user name and password means i got the given below error message thrice at a time ,
else { MessageBox.Show("Please check your username/Password or else check your Role", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
so please check my full code below and find out where i would made mistake in my code.
please drop a solution here..
code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace tarriff_design_page
{
public partial class sample : Form
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
SqlDataReader dr;
string s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=Database1.mdf;Integrated Security=True;User Instance=True";
public sample()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("select username,password from login", con);
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
string strname = textBox1.Text;
string strpwd = textBox2.Text;
if (dr["username"].ToString() == strname && dr["password"].ToString() == strpwd)
{
Home hpage = new Home();
hpage.Text = ("Welcome to ") + textBox1.Text + (" ") + System.DateTime.Now.ToString();
hpage.Show();
this.Hide();
}
else
{
MessageBox.Show("Please check your username/Password or else check your Role", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
dr.Close();
con.Close();
}
}
catch (Exception ex1)
{
}
}
if (checkBox3.Checked)
{
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("select username,password from role3", con);
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
string strname = textBox1.Text;
string strpwd = textBox2.Text;
if (dr["username"].ToString() == strname && dr["password"].ToString() == strpwd)
{
searchgv vd = new searchgv();
vd.Text = ("Welcome to ") + textBox1.Text + (" ") + System.DateTime.Now.ToString();
vd.Show();
this.Hide();
}
else
{
MessageBox.Show("Please check your username/Password or else check your Role", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
dr.Close();
con.Close();
}
}
catch (Exception ex1)
{
}
}
if (checkBox2.Checked)
{
try
{
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("select username,password from adminlogin", con);
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
string strname = textBox1.Text;
string strpwd = textBox2.Text;
if (dr["username"].ToString() == strname && dr["password"].ToString() == strpwd)
{
Admin ad = new Admin();
ad.Text = ("Welcome to ") + textBox2.Text + (" ") + System.DateTime.Now.ToString();
ad.Show();
this.Hide();
}
else
{
MessageBox.Show("Please check your username/Password or else check your Role", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
con.Close();
dr.Close();
}
catch (Exception ex)
{
}
}
}
}
}
thanks in advance...