- 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 = .\SQLEXPRESS;AttachDbFilename = |DataDirectory|\Database1.mdf;Integrated Security = True;User Instance = True"))
- {
- conn.Open();
- SqlCommand comm = conn.CreateCommand();
- comm.CommandText = "insert into MyTable1(Name)values('we9')";
- comm.ExecuteNonQuery();
- Console.WriteLine("数据插入成功");
- comm.CommandText = "select count(*) from MyTable1";
- Console.WriteLine(comm.ExecuteScalar());
- }
- Console.WriteLine("连接成功");
-
- Console.ReadKey();
复制代码 为什么修改了values的值,新插入的数据就会覆盖掉以前所有的数据。。。这怎么回事,求大侠指教!~~~
|