在vs2008里执行insert语句,程序运行显示插入成功,但是数据表并没有更新插入后的数据,为什么?
附上主要代码,请大家帮我看看。using(SqlConnectionconn=newSqlConnection(@"Datasource=.\SQLEXPRESS;Att...
附上主要代码,请大家帮我看看。
using (SqlConnection conn = new SqlConnection(@"Data source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=true;User Instance=true"))
{
conn.Open();
Console.WriteLine("OK"); //如果有显示,说明数据库连接成功
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "insert into T_User(UserName,Password) values('abc','123')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功!");
}
Console.ReadLine();
} 展开
using (SqlConnection conn = new SqlConnection(@"Data source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=true;User Instance=true"))
{
conn.Open();
Console.WriteLine("OK"); //如果有显示,说明数据库连接成功
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "insert into T_User(UserName,Password) values('abc','123')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功!");
}
Console.ReadLine();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询