Asp.Net and Queries

This post is more than 2 years old.

So, I'm slowly learning Asp.Net when I've got a few free minutes here and there. Somethings really impress me. The UI Form control are nice, and I love being able to tie functions directly to event handlers. It has a real... tight feel that CF does not (in most cases, not all).

One thing that doesn't make sense though (and again, I'm still learning so this may become more obvious later on) is why MS didn't spend any time making a simple asp:query tag. From what I see, using a query is still not as simple as CF. (To be honest, I've not seen any language do query/query output as well as CF.) Performing a query, and then looping over it, should be as easy as their calendar tag or other form controls. Sure its easy to tie a query to a pretty data sheet, but why not make getting the query just as easy.

In many ASP versus CF comparison charts, the ease of use of queries has come up many times. I have to wonder why MS didn't reconignize this.

So, those of you who develop in ASP, what do you do? Do you design your own controls, or functions, to simplify performing queries? How about then using the query result sets?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Dan posted on 11/6/2003 at 12:33 PM

This is a fair criticism of ASP.NET.

The way I have got round it in the past is to create a generic data access class, that has methods such as Execute(SQL), GetDataTable(SQL), GetDataSet(SQL,TableName), which is persistied througout the life of the application.

All is neccessary to get a datatable is to make a call to the class

e.g. tblProducts = clsData.GetDataTable(SQL)...

Within the constructor for the clsData class are all the neccessary gubbins that need to be set up to create a connection etc, and within the relavant methods is all the code neccessary to open a connection etc, populate the table.... close the connection (if required)

Its quite a hassle - but only has to be done once - and abstracts many datasource specifc requirements (different classes for accessing SQL server and non SQL server db's for instance)

I then inherit from this class, having an application specific data class for each application - and have as much of possible of my direct data access hapenning through this class, and only access the db through strongly typed objects based on this app_data class...


Comment 2 by Brian posted on 11/7/2003 at 2:45 AM

I think its good to keep in mind that ASP.Net is a version 1 technology and for what I'm seeing with ASP.Net 2 and the Object Spaces implementation-- as much as it kills me-- will be far better than anything possible with CF currently.

Comment 3 by Kwang Suh posted on 11/7/2003 at 3:31 AM

As Dan said, I also wrote a wrapper class for db access. MS does provide one as well on their website. As it was still a little too low level for me, I actually wrote my wrapper class around those classes.

If you wish, I can provide you with the source. It's very straightforward.

Comment 4 by Raymond Camden posted on 11/7/2003 at 6:39 PM

Thanks for the offer. Right now I want to take it slow. First I want to get comfortable doing things the "slow" way.

Comment 5 by barry.b posted on 8/2/2004 at 4:28 PM

Ray, I don't know if you're still reading this post but... a (former) ASP'er who's gone over to CFMX (since it's release as Neo), I feel CFQUERY is inadequate compared to ASP.NET's ADO.

I *like* having direct control over the connection object and the execution of queries. I worry about the hiding behind CFQUERY esp when it comes to connection pooling, transactions and record locking, etc.

I really miss ADO.NET and I don't think CFQUERY is as flexable even if it has less code to write.

now if I could get to and use the underlying java classes directly...

just 2c worth

Comment 6 by ike posted on 1/5/2009 at 10:02 PM

Wow. I hesitate to comment on a 4 year old blog entry... But if you really need or (imo more likely) want to control connection pooling and the like yourself, it's none too difficult to write your own Java classes and completely bypass the ColdFusion DSN and it's CFAdmin configuration. There are a handful of companies (none that I've worked for personally) who write their entire business model in Java and only use CF for the presentation tier.

Personally I've never heard of anyone having a significant problem related to connection pooling, so I'm not apt to be worried about problems I've never heard of actually happening to people.

Transaction handling and record locking on the other hand have some native features. Look for the cftransaction tag, or if you need to coordinate with other code outside the db, check out cflock. Plus there's always the ability to use stored procedures (cfstoredproc) if you have a particular need for really fine-grained control over the transaction -- that gets you "down to the metal" where the database is concerned, since the control is internal within your db server versus external manipulation with cftransactuion.

Comment 7 by Misty posted on 10/20/2010 at 4:51 PM

wELL! dO NOT KNOW WHAT TO SAY! TRIED TO DO ASP.NET many a times but could find it better than CF. Although its features are too great than CF but i Prefer CF [Don't Know Why]..

Can anyone answer!