ConnectionString in QueriesTableAdapter

G

Guest

How can I change the ConnectionString in QueriesTableAdapter? I have some
queiries which returns scalar values in QueriesTableAdapter in DataSet, but I
am not able to change connectionString. How can I do that?

I know, I can create SqlCommand and set Connection manually, but after that
I have to take a question: What use is this QueriesTableAdapter with queries?
 
M

Mark

The connection string is a property of each item within the
QueriesTableAdapter, not the QueriesTableAdapter itsself.
 
G

Guest

Thank you.

But: I have QueriesTableAdapter and one SqlCommand, for example:
DeleteInvoice.
How can I change connectionString for DeleteInvoice command?
I can't write: DeleteInvoice.Connection.ConnectionString = ...
It isn's possible. DeleteInvoice is method which calls SqlCommand. This
method uses ConnectionString from CommandCollection which is property of
QueriesTableAdapter! But this property is protected, no public!

Best regards
Jan
 
S

Sacher dos

We could not find a straight forward mechanism for updating the connectionString for the Commands in the QueriesTableAdapter. Still a roundabout way is there.

We have a protected property "CommandCollection" for "QueriesTableAdapter" class. This CommandCollection holds all the commands inside the QueriesTableAdapter. So, we inherited a class "XQueriesTableAdapter" from "QueriesTableAdapter". Now our XQueriesTableAdapter can directly manipulate the connectionStrings of the commands. Look at the code below. We need to pass the needed connectionString to the UpdateCommandConnections method of XQueriesTableAdapter.

************************************
public class GlobalQueriesTableAdapter : QueriesTableAdapter
{
public GlobalQueriesTableAdapter()
{
}

public void UpdateCommandConnections(string sConnString)
{
foreach (System.Data.IDbCommand BBXCommand in CommandCollection)
BBXCommand.Connection.ConnectionString = sConnString;
}
}
}
************************************

To call it use
oXQuerySet = new XQueriesTableAdapter();
oXQuerySet.UpdateCommandConnections(sConnStr);
*************************************

In our project, this works well. But we can still use the normal TableAdapters for doing the kind of work which we do using QueriesTableAdapters. So we are changing our code: that means we are removing QueriesTableAdapters and instead use the TableAdapters. So the original question comes back. Why the QueriesTableAdapters exist. What we feel is for the simplicity. You just drag and drop a stored procedure into the xsd file, and you get a perfectly working command object. No need to configure anything further. So for newcomers, this may be the best option.

Hope this post helps somebody.

Sacher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top