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
All generated TableAdapters inherit from Component. Therefore, you could write a method like this that uses reflection to extract the adapter property:
private void ChangeTimeout(Component component, int timeout)
{
if (!component.GetType().Name.Contains("TableAdapter"))
{
return;
}
PropertyInfo adapterProp = component.GetType().GetProperty("Adapter", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);
if (adapterProp == null)
{
return;
}
SqlDataAdapter adapter = adapterProp.GetValue(component, null) as SqlDataAdapter;
if (adapter == null)
{
return;
}
adapter.SelectCommand.CommandTimeout = timeout;
}
You then can call it like this:
MyTableAdapter ta = new MyTableAdapter();
this.ChangeTimeout(ta,1000);
I'm assuming that since you're using typed DataSet's that you're still in .NET 2.0 which is why I didn't bother making this an extension method.