悬赏园豆:10
[已解决问题]
解决于 2008-08-31 10:29
<P>这是微软petshop 4.0中的两个方法:</P>
<P> public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) {</P>
<P> SqlCommand cmd = new SqlCommand();</P>
<P> PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);<BR> int val = cmd.ExecuteNonQuery();<BR> cmd.Parameters.Clear();<BR> return val;<BR> }</P>
<P mce_keep="true"> </P>
<P>private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) {</P>
<P> if (conn.State != ConnectionState.Open)<BR> conn.Open();</P>
<P> cmd.Connection = conn;<BR> cmd.CommandText = cmdText;</P>
<P> if (trans != null)<BR> cmd.Transaction = trans;</P>
<P> cmd.CommandType = cmdType;</P>
<P> if (cmdParms != null) {<BR> foreach (SqlParameter parm in cmdParms)<BR> cmd.Parameters.Add(parm);<BR> }</P>
<P> 没有关闭连接,测试了下,我调用ExecuteNonQuery后,连接还是打开的,是不是故意这么设计,还是什么原因</P>