本帖最后由 李晶晶 于 2013-8-15 20:05 编辑
- 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();
- using (SqlCommand comm = conn.CreateCommand())
- {
- comm.CommandText = "Insert into MyTable1 (Name) values ('bc')";
- comm.ExecuteNonQuery();
- Console.WriteLine("插入成功");
- }
- }
- Console.WriteLine("连接成功");
- Console.ReadKey();
复制代码 上面是代码,运行的话,屏幕会显示“插入成功”“连接成功”,可是右键单击执行的时候,MyTabel1并没有显示我插入的这条数据,怎么回事啊?????
|