Inderjeet Singh

Inderjeet Singh

  • NA
  • 232
  • 723

Show message "You are already logged in" upon RE-login?

Nov 27 2018 11:48 PM
I am new to C# and building  a login form,i want to show below message if user is already logged in and try to login again.
how to show message "You are already logged in" if user attempt to login again.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Login
{
public partial class LogIin : Form
{
public LogIin()
{
InitializeComponent();
}
private void LogIn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=IBMPC\SQLEXPRESS;Initial Catalog=UserData;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from User_Credential where UserName = @UserName and Passwords = @Passwords",con);
cmd.Parameters.AddWithValue("@UserName", UsTxt.Text);
cmd.Parameters.AddWithValue("@Passwords",PassTxt.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
Welcome_Form wf = new Welcome_Form();
wf.Show();
}
else
{
MessageBox.Show("Please enter Correct Username and Password");
}
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

Answers (2)