Tuesday, April 3, 2007

SqlDataSource

I used the SqlDataSource for the first time today. I switched jobs and now I'm the only developer in the company. It's something I would hate to do if I thought someone else would see it or anyone (myself included) would have to maintain it. I needed to grab html out of the database and spit it onto the page and I did the quickest way I could think of: a SqlDataSource and a Repeater. The Repeater is pretty bad too because there will never be more than one record, but it was quick and it worked. Is the "proper" alternative to load the data in the code behind and stuff it into a literal? Too much work and no gain.

I've posted about unit tests and patterns recently because I thought that I'd need to be more vigilant because I'm the only developer. That may be so for more complex tasks, but spitting out the result of "SELECT html FROM dhtml WHERE id = 4" isn't complex enough to warrant that. I'll need to revisit it when I implement the page that lets you edit the html and I'll rewrite it then if necessary. By then, I'll have SubSonic ready to go.

I'll take the quickest and easiest path, as long as it's reliable.

UPDATE: I took them out today. I had two different kinds of SqlDataSources. One was easier to replace with one line in the code behind. I'm always in favor of less code. The other needed to be rewritten and it required more logic. It was in 4 places so I replaced it with a controller.

No comments: