VentureFree
Well-known member
- Joined
- Jan 9, 2008
- Messages
- 54
- Programming Experience
- 5-10
I'm new to using datasets and I'm not sure if I can actually accomplish what I'm trying to do, so I want to verify before I mess something up.
Basically, if I create a dataset called MyDataSet in my data access layer at build time pointing to a table called MyData, and I have two different databases that it could potentially point to (i.e. MyDatabase and MyTestDatabase which is essentially an exact copy of MyDatabase purely for testing), can I decide at run-time which database to point to?
My initial guess is that I can simply change the ConnectionString at run time and have it connect to whichever one I want. For example, I could do the following:
At this point, since MyTestDatabase is basically an exact copy of MyDatabase, any Updates/Inserts/Deletes/etc... should affect the test database and not the original database without having to include any other code, right?
Or would that cause problems since I created the data set at build time meaning it's expecting that specific connection string?
Basically, if I create a dataset called MyDataSet in my data access layer at build time pointing to a table called MyData, and I have two different databases that it could potentially point to (i.e. MyDatabase and MyTestDatabase which is essentially an exact copy of MyDatabase purely for testing), can I decide at run-time which database to point to?
My initial guess is that I can simply change the ConnectionString at run time and have it connect to whichever one I want. For example, I could do the following:
VB.NET:
Dim MyTable As MyDataSet.MyDataSetDataTable
Dim MyAdapter As New MyDataSetTableAdapters.MyDataTableAdapter()
' Assuming that MyAdapter has a Connection String already defined which points it to MyDatabase
If (Me.Testing = True) Then
'TestConnectionString is a connection string that points to MyTestDatabase
MyAdapter .Connection.ConnectionString = TestConnectionString
End If
' The following should get data from the original database if Testing = False, and from the test database if Testing = True, right?
MyTable = MyAdapter.GetData()
Or would that cause problems since I created the data set at build time meaning it's expecting that specific connection string?