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
for some reason, my adapter's .selectcommand was null so i ended up having to go through the CommandCollection object instead, so i thought i'd post my small change based on the previous answer above.
includes:
using System.ComponentModel;
using System.Reflection;
code:
private void ChangeTimeout(Component component, int timeout)
{
if (!component.GetType().Name.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;
}
command[0].CommandTimeout = timeout;
}