Making Generic DB Methods w/ SqlCommand.Executexxx()

wyrd

Well-known member
Joined
Aug 23, 2002
Messages
1,408
Location
California
Ive been using SqlCommand.Executexxx because I didnt want to get into a mess with DataSets just yet, especially since my current db program is fairly simplistic and the db will be on the same computer as the program.

Anyway, my question is about making generic db methods for accessing data (so I can just include them and use them in any program w/ little set up and effort). To do this, it seems that Id need to create methods that return the result set in some fasion.

My first thought was returning the SqlDataReader, but thats a little silly since if I was going to do that, Id have to close the connection and SqlDataReader ouside of the generic method. Sort of defeats the purpose.

So, my second thought was to return an ArrayList of sorts, but wouldnt that be the same as returning a DataTable except Im adding more looping to it, because I have to loop through the SqlDataReader of retrieved rows? Im not sure how SqlDataAdapter works with fill, perhaps it does use a loop to fill the returning DataTable too?

Well anyway, does anyone have any suggestions, or would I be best moving to DataSets w/ SqlDataAdapter if I want to make good generic db methdos?

Thanks in advance.
 
What I suggest is to create a class that can have many methods, you can return Datasets, DataTables, Arraylists, classic Arrays.

For things like .Fill or .Databind, I left that out of my class, I prefer not to expose it to controls.
 
Back
Top