I've been trying to make a login form to my database for a mobile shop store (university project). I have an Employee table containing Emp_name and Emp_password as id and password to then access the database. This is the code but somehow I created the design and when I click on the log in button it doesn't write any message for me. Please tell me how to let this login form launch the database separately of mysql server
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace login_form
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection();
public Form1()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=RAYMOND-PC;Initial Catalog=[mobile shop final];Integrated Security=True";
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'sTUDENTDataSet.login' table. You can move, or remove it, as needed.
//this.loginTableAdapter.Fill(this.sTUDENTDataSet.login);
SqlConnection con = new SqlConnection("Data Source=RAYMOND-PC;Initial Catalog= mobile shop final;Integrated Security=True");
con.Open();
{
}
}
private void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=RAYMOND-PC;Initial Catalog=mobile shop final;Integrated Security=True";
con.Open();
string Emp_name=textBox1.Text;
string Emp_password = textBox2.Text ;
SqlCommand cmd = new SqlCommand("select Emp_name , Emp_password from Employee where Emp_name='" + textBox1.Text + "'and Emp_password='" + textBox2.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
SqlDataReader dr;
dr = cmd.ExecuteReader();
da.Fill(dt);
if (Emp_name == textBox1.Text && Emp_password==textBox2.Text)
{
MessageBox.Show("Login sucess Welcome to Mobile shop");
System.Diagnostics.Process.Start("mobile shop final");
}
else
{
MessageBox.Show("Invalid Login please check username and password");
}
con.Close();
}
private void Button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
}
}
}