Question How to get application's Connection for general query/DML purpose

afh

Member
Joined
Jul 10, 2017
Messages
15
Programming Experience
5-10
I am developing a Sales application with MS Access Database. I've added Data Source through wizard and created forms with Data Set.


It is sometimes required to do some other query/dml inside the form code. Is it possible to use the same Connection as my application is using or I've to open a new connection based on my settings and perform a query/DML e.g.


Code:
Dim conn As New OleDb.OleDbConnection(WindowsApplication1.My.Settings.salesConnectionString)
conn.Open()
 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,111
Location
Sydney, Australia
Programming Experience
10+
Your application isn't using just one connection anyway. Each table adapter object you create will create its own connection object internally, so there's no real benefit to trying to reuse one of them yourself.

Also, you only need to create your own ADO.NET objects if the SQL is generated dynamically. Anything you know at design time can be incorporated into your typed DataSet. You can add more queries to the existing table adapters to add filters and you can even add more table adapters and DataTables, e.g. if you need to show data from a join.
 

afh

Member
Joined
Jul 10, 2017
Messages
15
Programming Experience
5-10
Thanks for such a clear answer.
 
Top Bottom