Run Action Query with VB.NET

I created an action query in MS Access and i would like to run that same query from VB.Net.  Since I need to run the code in multiple spots in my application, I would like another alternative than:

dim myStr as string = "Update ....."
dim myCmd as new command(mystr, myConnection)

mycmd.executenonquery()
LVL 8
rodmjayAsked:
Who is Participating?
 
amyhxuCommented:
If you have several forms, you can put the method in a module, so it's global and can be accessed within the whole program.

Module Module1

    Public Sub UpdateDb(ByVal myConnection As OleDbConnection)
        dim myStr as string = "Update ....."
        dim myCmd as new command(mystr, myConnection)
        mycmd.executenonquery()
    End Sub

End Module

You can call UpdateDb(myConnection) from anywhere inside the application.

If you only have one form, then write it as a method, and call it from other subroutines.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.