Code Re-use or classes

R

robopro

I've been coding in asp.net (vb) for a while now and I miss being able
to create functions in modules (like in ms access) so that I don't
need to reuse my code in all the code behind pages. I know that
creating classes is the accepted way to get around this in .net but I
have not been able to find documentation that can get me to where I
want to be. I'd like to have a class that will have a couple data
centric functions, like a function to execute an update string in sql,
or a function to return a dataset or datatable.
the only classes I've seen examples of return things like text boxes,
I'm looking to perform a database action and either return success or
return the result of a query.

Has anyone done this? or does everyone have multiple copies of blocks
of code that just connect to a db and return the datasets?
 
D

Dan Bass

Code reuse is always bad... Why? Well because if you need to change
something, you have to search for all the places you've used that code to
make the change. If everything's central, it's far clearer, and much easier
to change.

You can do the same thing as you did with modules in classes, all you need
to do is create a new class, and create a "public static sub" or "public
static fuction", then reference this directly without having to create the
class, just as you would when accessing modules...

<MyClass>.<MyStaticPublicFunction>

Thanks.

Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top