In this chapter, David tries to move the ark of the covenant to Jerusalem.
This chapter is almost entirely copied from 2 Samuel 6, so it has a very similar purpose in the text, demonstrating David's devotion to the LORD (and at the same time, showing that king Saul was not concerned with the presence of the LORD). In Chronicles, this section immediately follows the coronation banquet in chapter 12, which makes it appear as if this was David's first action as king. Samuel tells the story slightly differently, but I don't think the difference is significant.
In broad terms, the picture I see here is David's exuberance and passion for God causing all the people to celebrate just as hard (v. 8), but the turn of events in v. 9 is striking. Even though the people are celebrating God and joyful, they are acting ignorantly of God's command in the Law of Moses. In particular, Numbers 4:15 specifically states that the holy things (including the ark) are not to be touched, but they were supposed to be carried on poles that would be placed on the shoulders of the Levites. This is how they were carried throughout Israel's entire time wandering in the desert and this was specifically the ministry of the Levites. In this chapter, David and the Israelites made a critical mistake by placing the ark of the covenant on a new cart, mimicking the behavior of the Philistines (which is not discussed in Chronicles, but we read that story back in 1 Samuel 6:7).
The Philistines acted in ignorance, being unaware of the Law, and the Israelites also acted ignorantly, following the example of the Philistines. Even though it looks like Uzzah is doing a good thing (helping to keep the ark from falling), the people were acting contrary to God's command. If the ark had been carried by the poles, then this situation never would have come up.
David's fear of the ark is not entirely misplaced, but it does show that when he and the other Israelites interacted with the symbol of God's presence, they needed to treat it reverently and according to God's stated will. God's ark, like God's presence, is only dangerous if we approach it contrary to the path that God has made. This shows even more clearly in God's treatment of Obed-Edom, where this Levite (presumably) treats the ark well, and God blesses his whole household.
God struck down Uzzah to show that he must be respected, but he blessed Obed-Edom to show that he is not cruel. God is not capricious: he responds to these two men in accordance with how they treat his presence. David was afraid because he saw the first part (the death of Uzzah), but over time he will come to see the second part (that God desires to bless his people) and will eventually move the ark to Jerusalem. I think there are many people in the world who see God as the killer of Uzzah. They see a judgmental God that is just waiting for us to mess up and then destroy us when we make the smallest mistake. They don't see the God who blesses Obed-Edom, which is why it's so important that both stories are in the same chapter. We need to revere God, honor him, and approach his presence the way that he tells us to, but we also need to see that God isn't waiting to destroy us. He wants us to draw near so that he may bless us.
Even though the ark remains outside of Jerusalem, the blessing of God continues in the next chapter as David defeats the Philistines again.