问题描述
当我运行该SQL语句:
when I run this sql:
insert into table1(ID,Name) values ('10','Saeed');
好像是记录已被插入,如果我读通过表( SELECT * FROM表1
)它让我看到插入的记录,但是关闭程序后, ,它消失了。
it seems that the record has been inserted, and if I read the table using (select * from table1
) it shows me the inserted record, but after closing the program, it disappears.
这是code:
string constr="Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|" +
"\\Database1.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(
"insert into st (ID,Name) values ('10','saeed');", con);
cmd.ExecuteNonQuery();
cmd.Close();
我在里面手动插入一些记录,当我读到数据库中,手动插入记录存在。
I inserted some records in it manually, and when I read the database, the manually inserted records exist.
这是不是一个交易的问题不会被交易解决了!
It is not a transaction problem wont be solved with a transaction!
推荐答案
这个问题听起来像是你开始交易,忘了提交。但是,如果您正在使用的精确code你发布这不是一个交易的问题,因为你没有使用一个。
The issue sounds like you started a transaction and forgot to commit it. However, if you are using the exact code you posted this is not a transaction problem because you are not using one.
这让我觉得有一些时髦与您的连接字符串怎么回事。
That makes me think there is something funky going on with your connection string.
有关踢和笑声试图改变你的连接字符串,这样的事情
For kicks and giggles trying changing your connection string to something like this
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;
这篇关于在C#中插入的问题,使用的SqlCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!