本來想說搜尋看看有沒有人已經改過一樣的東西,找了一下沒找到,那就自己來吧。
主要也只是做一些改名字的動作,變動如下,
- SqlConnection -> IDbConnection
- SqlTransaction -> IDbTransaction
- SqlCommand -> IDbCommand
- SqlParameter -> IDbDataParameter
- SqlDataReader -> IDataReader
- SqlDataAdapter: 這個本來要改成 IDbDataAdapter 的,不過因為會用在 using() 之中,需要 IDisposable ,但 IDbDataAdapter 不包含它,所以我就沒改了。
public static int ExecuteNonQuery(IDbConnection connection, CommandType commandType, string commandText, params IDbDataParameter[] commandParameters)
{
if( connection == null ) throw new ArgumentNullException( "connection" );
// Create a command and prepare it for execution
IDbCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (IDbTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection );
// Finally, execute the command
int retval = cmd.ExecuteNonQuery();
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
if( mustCloseConnection )
connection.Close();
return retval;
}
程式碼下載位置:SQLHelper_InterfaceVersion.cs
沒有留言:
張貼留言