using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"))
复制代码
但是这样用,程序没效果,我改成绝对地址后:
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=e:\documents\visual studio 2010\Projects\exam2\test9\Database1.mdf;Integrated Security=True;User Instance=True"))