- 项目内嵌mdf文件形式的连接字符串 最好加在mian方法第一位置
- string dataDir = AppDomain.CurrentDomain.BaseDirectory;
- if (dataDir.EndsWith(@"\bin\Debug\")
- || dataDir.EndsWith(@"\bin\Release\"))
- {
- dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
- AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
- }
- ADO.NET经典案例
- 例1:插入数据:
- using (SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\C#程序\第二阶段\第二阶段\ADO.NET入门\AOD.net.mdf;Integrated Security=True"))
- // SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\C#程序\第二阶段\第二阶段\ADO.NET入门\AOD.net.mdf;Integrated Security=True"))参数为连接字符串
复制代码 |