<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語句既有數(shù)據(jù)插入,又有數(shù)據(jù)查詢,在此情況下需不需要事務(以上是MS示例代碼)?如果需要該怎樣修改?謝謝。</P>
這樣的SqlDataReader需要事務嗎?
慕的地8271018
2018-12-12 14:05:38