Search code examples
c#visual-studio-2008data-access-layertableadapter

override the connection in table adapters - UpdateCommandConnection Method


I need to override the connection in my new table adapters, as they are currently using the connection strings used during development. (VS2008).

For instance, using an existing table adapter Orders as an example, the connection string gets overridden thus:

ta.UpdateCommandConnections(conn);
ta.OrderInsert(OrderId, .... etc etc) 

My Question is how does the UpdateCommandConnections method get created? It looks as though I've missed a step in my table adapter creation - through the designer....

using DataLibrary.DAL.dalOrdersTableAdapters;
using System;

namespace DataLibrary.DAL {


    partial class dalOrders
    {
        public class GlobalQueriesTableAdapter : QueriesTableAdapter
        {
            public void UpdateCommandConnections(string sConnString)
            {
                foreach (System.Data.IDbCommand idbCommand in CommandCollection)
                    idbCommand.Connection.ConnectionString = sConnString;
            }
        }
    }
}

When I manually add the UpdateCommandConnection function above (I also have to add the .cs file in the process) to one of my own table adapters it does not recognise the CommandCollection or QueriesTableAdapter, which have been added by the designer (in the existing Orders ta it’s definition is in the dalOrders.Designer.cs file).

What steps have I missed when creating my table adapters?

Many thanks


Solution

  • Just to clear things up...

    In the above example the QueriesTableAdapter is the name of the table adapter, so amending this to the name of my table adapter (or renaming my table adapter to QueriesTableAdapter) did the trick.