Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is probably going to boil down to a philosophical question more than anything, but is there really any major difference between using the <asp:sqldatasource> in the aspx file versus doing all of the work in the code behind?

If so what are they and why? I know I have my preferences, but I am just curious what others think.

Edit:

I purposely didn't put my preference in which is to put as much as possible in the code behind or even DAO. I was curious what others thought since I am going to have to update a bunch of code that has sqldatasource calls all over of the apsx files.

Thank you everyone who responded. I appreciate your input.

share|improve this question
    
Don't reinvent the wheel? –  asawyer Jul 8 '11 at 20:48
2  
You should not use SqlDataSource but ObjectDataSource apart from testing/quick hacks. stackoverflow.com/questions/1207295/… –  Tim Schmelter Jul 8 '11 at 20:49
    
possible duplicate of Declarative databinding vs. ADO.NET in code-behind –  Tim Schmelter Jul 8 '11 at 21:02
add comment

3 Answers

up vote 2 down vote accepted

Embedding your SQLDataSource within the asp.net page is coupling your presentation layer with your data access layer resulting in reduced testability and flexibility. I strongly suggest moving your data connections to their own classes and created a data access layer that your code behind pages could then draw from.

Ideally you'd seperate this even further into an N-Tier solution. Link

share|improve this answer
add comment

For a simple application there isn't any reason not to use a asp:sqldatasource, but lots of developers want to separate the specifics of there data access strategy from the view logic.

What if you wanted to switch to an ORM like nHibernate? You would have to go rip out all the asp:sqldatasource from your aspx pages. If you did your wireing up in the code behind you wouldn't have to touch the aspx pages. If you abstracted even further, say into DAOs, you wouldn't even have to touch your code behinds, you could switch out your DAOs.

share|improve this answer
add comment

SqlDataSource.

I'll tell you considering what I think are Major Differences:

  • Ease of use
  • Time consume
  • Reliability
  • Other features
  • Ease of use

And...

  • Ease of use.
share|improve this answer
    
I don't see what you prefer and why only notes without explanations. –  Tim Schmelter Jul 8 '11 at 20:59
    
I edited to include what I prefer, and I still don't think what I listed need further explanation. –  Smur Jul 11 '11 at 11:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.