How can I change the table adapter's command timeout

后端 未结 15 1403
遇见更好的自我
遇见更好的自我 2020-12-10 02:12

I\'m using Visual Studio 2008 with C#.

I have a .xsd file and it has a table adapter. I want to change the table adapter\'s command timeout.

Thanks for your

15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 02:56

    Call ChangeTimeout Function by providing the TableAdapter and Time in seconds.

    this.ChangeTimeout(this.taTest, 500);
    

    Function :

     private void ChangeTimeout(Component component, int timeout)
    {
        if (!component.GetType().FullName.Contains("TableAdapter")) { 
            return;
        }
    
        PropertyInfo adapterProp = component.GetType().GetProperty("CommandCollection", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);
        if (adapterProp == null) {
            return;
        }
    
        SqlCommand[] command = adapterProp.GetValue(component, null) as SqlCommand[];
    
        if (command == null) {
            return;
        }
    
        Interaction.command(0).CommandTimeout = timeout;
    }
    

提交回复
热议问题