ADO Update Code Re use

V

Vayse

I don't know about you, but I'm use similiar code again and again to update
my Datatables. So I just thought of something - shouldn't I just put all the
update code in one place?
I don't have access to VS2005 on this PC, but I was thinking of something
along these lines

'***************************************************************
Function FillTable(stSQL as string) as Datatable
' Open Connection
' Create data adapter
' Fill Datatable
' Close connection
End Function

Function UpdateTable(stCommandText as string, Params as Parameters, dtUpdate
as Datatable) as long
'Open Connection
'Create data adapter
'Create Updatecommand with stCommandText and the parameters collection
'Have the adapter run the command
' Close connection
'Return number of rows updated
End Function

To use these functions, have something like
Dim stSelect as string = "Select CustomerID, CustomerName, CustomerSales
FROM Customer"
Dim dtCustomer as new Datatable = Filltable(stSelect)
' Do processing
' Create parameters
Dim stUpdateText as string = "UPDATE Customers SET CustomerSales = ? WHERE
CustomerID = ?"
Dim lRows as Long = Updatetable(stUpdateText, paramsCustomer,dtCustomer)
'***************************************************************

Hope that made sense! Could also have Add and Delete functions.
Are any of you already doing something similiar?
Let me know if you think of anything I may be missing.
Thanks
Vayse
 
S

Scott M.

How about taking this one step further and making those functions part of a
stand-alone class and violla! You now have your own custom data class.
 
C

Cor Ligthert [MVP]

Vayse,

I assume it is not Ado which is to ADONET as a car like a plane.(all are to
transport).

If you want this nicely done, than you can open a component instead of a
form. You can than even do it draging, but as well in code. By instance the
Idisposable implementation is than by instance already coded for you.

I hope this helps,

Cor
 
V

Vayse

Of course, adonet. :)

Cor Ligthert said:
Vayse,

I assume it is not Ado which is to ADONET as a car like a plane.(all are
to transport).

If you want this nicely done, than you can open a component instead of a
form. You can than even do it draging, but as well in code. By instance
the Idisposable implementation is than by instance already coded for you.

I hope this helps,

Cor
 
H

Hendrik

Yes - the code re-use is def the way to go.

We created our own classes which handles calls to the database. We took
this further and made it database independant. We use this in every
application we do - and this makes developement a lot quicker. Also by
splitting the UI and Logic, we can throw any interface on our
application. We have one which has a normal windows UI, a Web UI and
extended also to a Progress UI.
Do yourself a favour and read up a bit on 3-Tier type applications.
(Database / Business logic / User Interface). This will give you some
interesting viewpoints regarding what you descibe above.
 
V

Vayse

Scott M. said:
How about taking this one step further and making those functions part of
a stand-alone class and violla! You now have your own custom data class.
I'm trying, but can't seem to get the parameters to pass to the class. See
my other thread above - Passing Parameter Collections.
If I get that working, I'll have my class.
I'll post it here when I get it working.
Vayse
 

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

Top