我无法弄清楚这是否是可接受的操作.我需要从sql Server 2008数据库中选择记录,然后删除它们,所有这些都是ASP.NET代码中的单个事务.请注意,.NET代码必须能够检索首先选择的数据.
这样的东西:
SELECT * FROM [tbl] WHERE [id] > 6; DELETE FROM [tbl] WHERE [id] > 6
SELECT * FROM [tbl]
编辑按照下面的要求,这里是检索记录的完整.NET代码:
string strsqlStatement = "SELECT * FROM [tbl] WHERE [id] > 6;" + "DELETE FROM [tbl] WHERE [id] > 6"; using (sqlCommand cmd = new sqlCommand(strsqlStatement,connectionString)) { using (sqlDataReader rdr = cmd.ExecuteReader()) { while(rdr.Read()) { //Read values val0 = rdr.GetInt32(0); val3 = rdr.GetInt32(3); //etc. } } }