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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox2.PasswordChar='$'; textBox2.MaxLength = 8; }
private void button1_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication1\WindowsFormsApplication1\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30"); con.Open(); SqlCommand cmd = new SqlCommand("Select * from Users where Username='" + textBox1.Text + "' and password='" + textBox2.Text + "';", con); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
int count = 0; while (rdr.Read()) { count = count + 1; } if (count == 1) { MessageBox.Show("username and password is correct"); } else if (count > 1) { MessageBox.Show("Username and password is duplicate..."); }
else MessageBox.Show ("username and password is incorrect"); con.Close(); } catch(Exception ex)
using System;
ReplyDeleteusing 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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox2.PasswordChar='$';
textBox2.MaxLength = 8;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication1\WindowsFormsApplication1\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Users where Username='" + textBox1.Text + "' and password='" + textBox2.Text + "';", con);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
int count = 0;
while (rdr.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("username and password is correct");
}
else if (count > 1)
{
MessageBox.Show("Username and password is duplicate...");
}
else
MessageBox.Show ("username and password is incorrect");
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
}
}
}