execute stored procedure in a class
Hi vbforums. Im a vb 6 newbie. Is it advisable to execute a stored procedure
inside a class
for example:
form
-------------------------
set cSaveDB = new clsSave
cSaveDB.SetName = txtName
cSaveDB.SetAge = txtAge
cSaveDB.WritetoDB
class module
-------------------------
Public Sub WritetoDB
set qy = new ADODB.command
Set qy.activeConnection = cn
qy.commandtext = "sp_Save"
qy.commandType = adCmdStoredPRoc
with qy
.value(1) = Name
.value(2) = Age
end with
set rs = qy.Execute
End Sub
is this a good practice in using class module?
Thanks a lot
Re: execute stored procedure in a class
The fact that your seperating out the data layer from the presentation is a good thing.
but...
As your a newbie, i would suggest you consider forgetting about VB6 and learning VB.NET instead as VB6 is getting long in the tooth! ;)
Re: execute stored procedure in a class
Yes, keeping the sql in the database and not in the code is definitely the better way to go. When you make changes to the database in the future you can easily list all of your stored procedures and make appropriate updates. It is much easier than searching millions of lines of code to find sql statements.
Re: execute stored procedure in a class
you may want to read our DB FAQ and tutorial thread... has lots of info for the beginner.
-tg
Re: execute stored procedure in a class
Thanks a lot for all your tips. It helped me a lot thinking of new concepts.