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 (System.Data.SqlClient.SqlConnection conn = new
System.Data.SqlClient.SqlConnection(@"Data source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;integrated security=True;user Instance=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Insert into Table1(Name,Pass) values('abc','123')"; //在Table1中插入数据,并且运行成功了,刷新执行后为什么在Table1表中看不到数据??
如何才能看到,急、急!!!!
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功!");
}
}
Console.WriteLine ("打开成功");
Console.ReadKey();
|