悬赏园豆:10
[已解决问题]
解决于 2008-07-21 15:11
<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>