大家好,我是新手,刚遇到一个连接数据库的问题
为什么能显示插入成功,但是数据库中却没有插入到的数据,这是为什么namespace 数据库
{
class Program
{
static void Main(string[] args)
{
string dateDir = AppDomain.CurrentDomain.BaseDirectory;
if (dateDir.EndsWith(@"\bin\Debug\") || dateDir.EndsWith(@"\bin\Release\"))
{
dateDir = (dateDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DateDirectory", dateDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
= "insert into Table1(names)values('aaa')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功");
}
}
Console.ReadKey();
}
}
}