I have the same problem also.
When I search for access points my Wii picks up my router and I enter the WEP key, run the test connection, and it says its fine. It even downloads the updates. But when I try to access any of the online channels (shop channel, opera browser, weather, etc.) it fails to connect and gives me that same error code 51331.
I came to the conclusion that you need a really strong signal to keep a wifi connection on the Wii. I heard if you get the LAN adapter it makes for a much more reliable connection, but I have yet to get one.