C#初始化字符串的格式不符合规范错误

时间:2017-06-25 15:33:28

标签: c#

我有一个抛出错误的C#代码:

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");
            }

此代码抛出(初始化字符串的格式不符合规范)错误,那么我该如何解决呢? enter image description here

1 个答案:

答案 0 :(得分:3)

SqlConnection需要连接字符串,而不是文件的路径。请参阅this questionthe documentation