I get an error on this line of code:
sda.Fill(dtbl);
Error message:
An attempt to attach an auto-named database for file C:\Users\...\Downloads\...\hax.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
I have looked into this thread before and it did not solve my problem! Still broken.
I am a newbie to C# and this is my first SQL Server database. So I don't really know what to do. Here are some screenshots of the tables as well
- https://gyazo.com/7558d5862d50a175b87861ac83cd34a4
- https://gyazo.com/89c23bf3d499d2ff6f7fc361ff2aa283
Code:
private void button1_Click(object sender, EventArgs e)
{
    SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \Users\...\Downloads\...\hax.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)
    {
        Form1 objFrmMain = new Form1();
        this.Hide();
        objFrmMain.Show();
    }
    else
    {
        MessageBox.Show("Check your username and password");
    }
}
private void button2_Click(object sender, EventArgs e)
{
    this.Close();
}
 
     
     
    