我是C#的新手,所以请原谅我。我试图写一个SqlConnection
,但是下面的代码显示db路径开始处的红线。我已经从数据库的连接字符串复制了路径。这让我很头疼。任何帮助将不胜感激。
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="D:\projects\Clinic POS\Clinic POS\Inventory.mdf";Integrated Security=True");
答案 0 :(得分:2)
您应该删除文件名周围的引号:
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\projects\Clinic POS\Clinic POS\Inventory.mdf;Integrated Security=True");
答案 1 :(得分:0)
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\projects\\Clinic POS\\Clinic POS\\Inventory.mdf;Integrated Security=True");