<P>strSQL.Append("INSERT INTO LineItem..."); </P> <P>conn.Open();<BR>cmd.Connection = conn;<BR>cmd.CommandType = CommandType.Text;<BR>cmd.CommandText = strSQL.Append("SELECT @ID, @ERR").ToString();</P> <P><BR>using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {<BR>rdr.Read();<BR>// If the error count is not zero throw an exception<BR>if (rdr.GetInt32(1) != 0)<BR>throw new ApplicationException("DATA INTEGRITY ERROR ON ORDER INSERT - ROLLBACK ISSUED");<BR>}</P> <P>上面代码中SQL语句既有数据插入,又有数据查询,在此情况下需不需要事务(以上是MS示例代码)?如果需要该怎样修改?谢谢。</P>
2 回答
- 2 回答
- 0 关注
- 736 浏览
添加回答
举报
0/150
提交
取消