I'm creating a login window in c# with SQL server following this guys tutorial https://www.youtube.com/watch?v=NX8-LhgFnUU
I did everything like he did but I get an error in my code when I debug the app and type username and password and click login. It brings me to code which is this code / screenshots:
Code:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\eAlati - 1366x768\FastFoodDemo\DB\logindb.mdf;Integrated Security=True;Connect Timeout=30");
string query = "Select * from Table Where username = '" + txtUsername.Text.Trim() + "'and password = '" + txtPassword.Text.Trim() + "'";
SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
if(dtbl.Rows.Count == 1)
{
ucitavanje objUcitavanje = new ucitavanje();
this.Hide();
objUcitavanje.Show();
}
else
{
MessageBox.Show("Vaše korisničko ime ili lozinka nisu točni! Pokušajte ponovno");
}
}
Thanks for understanding :)