Enzo Enzo

Enzo Enzo

  • NA
  • 26
  • 2.6k

An unhandled exception of type 'System.Data.SqlClient.SqlExc

Jan 17 2017 12:20 PM
 
 
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 test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server = localhost; user id = root; password=admin1234; database = test");
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM users where username = '" + txtusername.Text + "', and passw =' " + txtpassword.Text + "'", cn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
int count = 0;
while (dr.Read())
{
count += 1;
}
if (count == 1)
{
MessageBox.Show("OK");
Form2 f2 = new Form2();
f2.Show();
}
else if (count > 0)
{
MessageBox.Show("Duplicate username and password");
}
{
MessageBox.Show("username or password note correct");
}
txtusername.Clear();
txtpassword.Clear();
}
}
}

Answers (9)