-3

I hava a C# code that throwing an error:

SqlConnection sq = new SqlConnection(@"C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2012\PROJECTS\LOGINAPP\DB\LOGINDB.MDF");
            string q = "Select * from Table where textBox1= '" + textBox1.Text.Trim() + "'and Password'" + textBox2.Text.Trim() + "'";
            SqlDataAdapter s = new SqlDataAdapter(q, sq);
            DataTable d = new DataTable();
            s.Fill(d);
            if (d.Rows.Count == 1)
            {
                frmMain G = new frmMain();
                this.Hide();
                G.Show();
            }
            else
            {
                MessageBox.Show("Check your Username or Password or both");
            }

this code throwing (Format of the initialization string does not conform to specification) error, so how can i fix it? enter image description here

Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
M.Saif
  • 137
  • 1
  • 2
  • 6

1 Answers1

4

SqlConnection requires a connection string, not a path to a file. See this question and the documentation.

async
  • 1,537
  • 11
  • 28