Home  |  About  | Last |  Submit  |  Contact
AllQuests.com



Previous Question:  2010 April 23 Magenta Moon transient corona colour  Observing [END]Next Question:  Using barcode scanner in my app  Visual Basic .NET
Question VS 2010 Dataset connection. Where can change it in program ( VBForums Visual Basic .NET )
Updated: 2010-07-22 20:00:03 (6)
VS 2010 Dataset connection. Where can change it in program

I have a dataset that I created through the wizard, to pull the data and their types from the database tables and prevent some of the headaches of creating the tables and data types individually.

I am looking for where the database connection for the dataset is defined at so I can change this. The reason being is I have added a database connection dialog where the user will select the location of the database server and I am wanting to pass the connection string from what the user selects to the dataset so the dataset uses this as its connection string instead of the default one I defined in the wizard.

Where is this defined at so I can change it?

Answers: VS 2010 Dataset connection. Where can change it in program ( VBForums Visual Basic .NET )
VS 2010 Dataset connection. Where can change it in program

I assume it is as simple as this:

On loading my program I call the dialog and save the connection string as :
Code:
My.Settings.EMTRACConnectionString = dcd.ConnectionString
        My.Settings.Save()
Then before loading the dataset I set the connection of the table adapter manager to:
Code:
Dim myDataSetConnection As New System.Data.SqlClient.SqlConnection
        myDataSetConnection.ConnectionString = My.Settings.EMTRACConnectionString
        TableAdapterManager.Connection = myDataSetConnection
Is that all I needed to do or did I need to do that for all of my table adapters?

nlraley

VS 2010 Dataset connection. Where can change it in program

In our case here, we set the connection individually for each adaptor... but that's because much of our data comes from multiple sources (which is the idea behind datasets). I've never used the TableAdaptorManager in a dataset, so I don't know if that works or not. Try it an see. If it doesn't work, you could just revert to setting the connections individually on table adaptors as you use them.

-tg

techgnome

VS 2010 Dataset connection. Where can change it in program

Well, doesn't appear to be working that way. Anyone have any ideas? Here is what I have:
Code:
Dim myDataSetConnection As New System.Data.SqlClient.SqlConnection
        myDataSetConnection.ConnectionString = My.Settings.EMTRACConnectionString
        myDataSetConnection.Open()
        TableAdapterManager.Connection = myDataSetConnection
        KMLUSERFILESTableAdapter.Connection = myDataSetConnection
        KMLUSERINFOTableAdapter.Connection = myDataSetConnection
        KMLREGISTRATIONTableAdapter.Connection = myDataSetConnection

        ' Fill our UserInfo and Registration Data Tables
        Me.KMLREGISTRATIONTableAdapter.Fill(Me.EMTRACKMLDataSet.KMLREGISTRATION)
        Me.KMLUSERINFOTableAdapter.Fill(Me.EMTRACKMLDataSet.KMLUSERINFO)
However, the table adapters don't appear to be getting filled at all.

nlraley

VS 2010 Dataset connection. Where can change it in program

That's because the table adaptors don't contain any data in the first place. The DataTables are what should be getting filled.

Where do you have that code and where are you calling it from?

Here's generally how we do it:
Code:
Dim ta As New MyTypedTableAdapter
ta.Connection = our_connection_Manager ' in your example, this would be myDataSetConnection 
Dim dataMyNewDataTable As MyTypedDataTable = ta.GetData(Pass_Optional_Parameters_Here)
'Now my datatable has been filled
We usually wrap that up in a function that returns the appropriate type based on the data we're trying to load, and viola!

-tg

techgnome

VS 2010 Dataset connection. Where can change it in program

Maybe I wasn't being clear.

I have:
1 Data set EMTRACKMLDataSet
1 TableAdapterManager TableAdapterManager
3 TableAdapters KMLUSERINFOTableAdapter, KMLREGISTRATIONTableAdapter, KMLUSERFILESTableAdapter

I have 2 controls and 1 table on my form that use the EMTRACKMLDataSet. 2 Comboboxes drop down and are filled with information from the dataset. 1 is filled with all the UserIDs listed in the KMLREGISTRATION table in the EMTRACKMLDataset and the other is populated with Descriptions for the UserID selected in the UserID combo box using the Description found in the KMLUSERINFO table in the EMTRACKMLDataSet. The Description is bound to the selected UserID in the KMLREGISTRATIONTableAdapter. Finally I have 1 table in the form that is filled with information from the USERFILES table in the EMTRACKMLDataSet. It's information is populated via the FillBy method of the KMLUSERFILESTableAdapter.

I created the DataSet via the designer so my tables and all the data would be created with the right type and everything. In order to do that I had to create a connection to the dataset. Now that I have it filled with the information from the right tables I am wanting to allow the user to select where the database is at, and therefore need to change the connection that the dataset uses based on the connection string created in my Database connection dialog, I used the one on msdn that was released in January.

Now, I thought it would just be a matter of changing the connection of the table adapters, but apparently that is not the case. Where do I need to change the connection to get it to fill the tables?

nlraley

VS 2010 Dataset connection. Where can change it in program

Nevermind, it read the type for UserID as being System.Int32 instead of 64. Trying to preview the data led me to finding this. Changing it to the right value, System.Int64 fixed it. Thanks!

nlraley

Previous Question:  2010 April 23 Magenta Moon transient corona colour  Society for Popular Astronomy  Observing [END]Next Question:  Using barcode scanner in my app  VBForums  Visual Basic .NET

- Source: VS 2010 Dataset connection. Where can change it in program VBForums Visual Basic .NET
- Previous Question: 2010 April 23 Magenta Moon transient corona colour Society for Popular Astronomy Observing [END]
- Next Question: Using barcode scanner in my app VBForums Visual Basic .NET