Control TableAdapter Command Timeout Globally

前端 未结 4 552
失恋的感觉
失恋的感觉 2021-01-03 05:01

I have a DataSet with a QueriesTableAdapter. In order to control the SqlCommand.CommandTimeout I\'ve added a partial class called QueriesTableAdapter with a public method ca

4条回答
  •  日久生厌
    2021-01-03 05:54

    BFree and mark's similar solutions work well with reflection. Below is a slight refinement that I think yields neater code.

    You can also change the base class that the TableAdapter uses in the DataSet designer. You can change your TableAdapter's base class to MyTableAdapterBaseClass or similar to provide the functionality you need. You can make this change quickly on all your TableAdapters by doing a 'Find in Files' and replace on your DataSets' .xsd files.

    Instead of BFree's method on the caller with signature:

    private void ChangeTimeout(Component component, int timeout)
    

    you can then create a method on the callee TableAdapter's base class with signature:

    public void ChangeTimeout(int timeout)
    

提交回复
热议问题