class Program
{
static void Main(string[] args)
{
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);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\;AttachDBFilename=|DataDirectory|\Database1.mdf;
Integrated Security=true;user instance=false"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Insert into MyTable1 (Name) values('Lucy')";
cmd.ExecuteNonQuery();
Console.Write("插入成功!");
}
}
Console.WriteLine("打开数据库连接成功");
Console.ReadKey();
}
}
运行代码正常, 但是运行完以后出现以下情况:
C:\Documents and Settings\Administrator\桌面
刷新Database1.mdf的时候:
C:\Documents and Settings\Administrator\桌面
求大神解决问题, |