使用ms访问和c#进行多个查询
问题描述:
我有多个更新查询,它们更新表中的一行,所以就像锁定一行更新更改并解锁该行一样.
现在,我只执行一次,而不是执行3次executenonquery.
能做到吗...
谢谢..
I have multiple update queries which update a row in table ,so it is like lock a row update the changes and unlock the row.
Now instead of executing executenonquery 3 times i want to execute it only once .
Can it be done ...
Thanks You..
答
是的,查询需要用分号;"
分隔
例如:
Yes, the queries need to seperated by semi-colon ";"
eg:
string query = "insert into table1(x,y,z); update table2 set a = 23;"
OledbCommand cmd = new OledbCommand(query, connection);
.
.
.
cmd.ExecuteNonQuery();
是的,可以; Microsoft Access支持事务 [
Yes, it can be; Microsoft Access supports Transactions [^]and they work quite well.
Even so, if possible, useSQL Server Express
. It''s much more powerful than Access.
如果要同时执行多个查询,请使用所有语句创建sring并执行它.
喜欢:
If You want to execute multiple query same time then create sring with all statement and execute it.
Like:
string strQuery = " Insert into tbl values(1,1);Update tbl set fld=value where id=id;update tbl2 set fld=value where id=id;";