am trying to create a login form using sql and when the application runs, it crashes at
- da.Fill(dt);
- public partial class Form1 : Form
- {
- SqlConnection con = new SqlConnection();
- public Form1()
- {
- SqlConnection con = new SqlConnection();
- con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Xavier\Documents\Data.mdf;Integrated Security=True";
-
- InitializeComponent();
- }
- private void pictureBox4_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection();
- con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Xavier\Documents\Data.mdf;Integrated Security=True";
- con.Open();
- string Username = textBox1.Text;
- string Password = textBox2.Text;
- SqlCommand cmd = new SqlCommand("select userid,password from login where Username='" + textBox1.Text + "'and Password='" + textBox2.Text + "'", con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- this.Hide();
- Form2 f2 = new Form2();
- f2.Show();
- }
- else
- {
- MessageBox.Show("Invalid Login Credentials!");
- }
- }
- }
- }