Error Handling When Using Dictionary I have set up a Dictionary that calls on a class to fill a DataGridView via SQL statements.  The problem is in two (out of 5) instances the value passed HAS to be an integer, but the value comes from a textbox so it is being passed as string.  Before I set these Dictionaries up I was just using a switch statement that can be seen here.  In my switch statement I simply added: 

int n;
bool isNumber = int.TryParse(textBox.Text, out n);

if (!isNumber)
{
  MessageBox.Show("Input must be an integer");
  break;
}


to the two cases that needed the value to be an integer type.

Any idea on how I can add error handling to this? Preferably a message box that just says "value needs to be an integer".

    private void findScriptsQueryButton_Click(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection();
        string value = this.valueTextBox.Text;
        connection.ConnectionString = GetSqlConnection[serverComboBox.SelectedItem.ToString()];
        findScriptsDataGrid.DataSource = GetDataSource[findByComboBox.SelectedItem.ToString()](connection, value).Tables[0];
    }
    private static TableAdapters.FindScript dataSource = new TableAdapters.FindScript();
    private static readonly Dictionary&lt;String, Func&lt;SqlConnection, String, DataSet&gt;&gt; GetDataSource = new Dictionary&lt;String, Func&lt;SqlConnection, String, DataSet&gt;&gt;()
    {
        {"Target VDN", dataSource.FillByTargetVDN},
        {"Skill Group", dataSource.FillBySkillGroup},
        {"Translation Route Pool", dataSource.FillByTranslationRoutePool},
        {"Name", dataSource.FillByName},
        {"Label", dataSource.FillByLabel}
    };

    private static readonly Dictionary&lt;String, String&gt; GetSqlConnection = new Dictionary&lt;String, String&gt;()
    {
        {"SERVER01", ConfigurationManager.ConnectionStrings["csS01"].ConnectionString},
        {"SERVER02", ConfigurationManager.ConnectionStrings["csS02"].ConnectionString}
    };
In your data structure include a validator (this should probably be a Predicate&lt;String&gt;); most of the predicates will just return true, but the two that require integers will have a nontrivial validator that checks for integer.

So I guess the type should be Dictionary&lt;String, Tuple&lt;Func&lt;SqlConnection, String, DataSet&gt;&gt;,Predicate&lt;String&gt;&gt;