I've created a user login using MySql, however when I run the code ...
private void LoginButton_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(@"Data Source=HP\SQLEXPRESS;Initial Catalog=Inventory;Integrated Security=True");
string query = "Select * from User Where Username = '" + Username_txt.Text + "' and Password = '" + Password_txt.Text + "'";
SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
if (dtbl.Rows.Count == 1)
{
Dashboard mainForm = new Dashboard();
this.Hide();
mainForm.Show();
}
else
{
MessageBox.Show("Check your username and password");
}
}
i get the error of ...
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'User'. "
whilst it highlights " sda.Fill(dtbl);"
What I have tried:
re-writing the code, double checking connection