VB Common Code Placement

I'm a novice VB.Net developer trying to create a Web site with multiple forms.  They're working but now I need the ability from any of the forms to call on a common procedure to save things to a database.  What's the best way to accomplish this? Essentially each form will have a Save button and all information gathered on all the forms needs to be captured.
ejefferson213Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jtdebeerCommented:
There is quite a couple of ways of doing this but I prefer the following for flexibility:


       Dim SqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("DB").ToString)
        Dim SqlCmd As New SqlCommand
        SqlCmd.Connection = SqlConn

<!--CHANGE YOUR QUERY TO AN INSERT AND READ THE TEXTBOX VALUES IN -->
        SqlCmd.CommandText = "Select ServicesDescription from Services where ServiceID = '" + TextBox.Text + "'"

        SqlConn.Open()
        SqlCmd.ExecuteNonQuery()
        SqlConn.Close()



Hope that makes sense
0
ejefferson213Author Commented:
Thank you for your response but I obviously wasn't clear.  I went through the exercise of creating Save functions for the database on each of the forms (done in the Button Click event handler).  Realizing that when a user wants something saved, they don't want just that form's data saved but everything on all forms, I now need to find a way of accessing the information that's on all the forms in a common routine.  What should make this easy is that I've saved all the information in Session variables.  However, I'm not literate enough with VB and OO programming to know where this code can go.  I've tried creating a separate class and subroutine but it doesn't understand what Session is.  Perhaps it's as simple as an Inherit instruction or something.  Hope that clarifies it a bit better.
0
jtdebeerCommented:
Read all variables from the forms into Session Variables.
Then when user clicks save populate the database form the SessionVars.
With other words in your Insert statement use the SessionVars and not the form fields.
0
ejefferson213Author Commented:
Here is a more detailed description of my situation.  I have 6 forms used for collecting information, each with a Save button.  Id like to be able to call a SUBroutine from each form to save all the Session variables to database tables when the Save button is clicked. I dont want to place the same code within each forms .vb (button click event) file. Therefore, I tried adding a Class file to the application and creating a SUBroutine (so that I can call it from each Save button click event on each form) only to find out that Session is not understood (seen as an uninitialized, unknown variable: Name Session is not declared), thus I cannot reference my information to save it.  Im guessing this is a simple issue whereby I simply need to include/inherit something.  If I don't place this common code in a class file, where should I place it? (somewhere hopefully where I can reference the Session variables)
0
ejefferson213Author Commented:
Being notified of an open question.  No further postings therefore, I'll close this out and pursue a solution elsewhere.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.