ArgumentException in DataTable Select statement

Share

Under some circumstances, filtering a Datatable using its Select method may result in throwing following exception:
“Min (some value) must be less than or equal to Max (-1) in a Range object.”

This happens only for particular values when the columns in case are of unknown type resulting in filtering
string data with numbers. To avoid running into such a case, always supply the type of the column when
creating a Datatable:

            DataTable dtTest = new DataTable("Customers");
 
            // instead of
            //dtTest.Columns.Add("CustID");
            // use
            dtTest.Columns.Add("CustID", typeof(Int32));

Although is uncommon working with unspecified columns types, this situation may occur. If for any reason the Datatable structure is out of reach, being known that all loaded data will be treated as strings, a workaround for this is to delimit the values in select expression with single quotes:

            DataRow[] drs = dtCust.Select("StreetNo='" + _nStreetNo + "'");

or better yet, filter the Dataview to get same result, so instead of the line above, use:

            dtCust.DefaultView.RowFilter = string.Format("StreetNo = '{0}'", _nStreetNo);
            DataTable dtFiltered = dtCust.DefaultView.ToTable();

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

1 thought on “ArgumentException in DataTable Select statement”
  • Sergey says:

    Thanks for help.

    July 7, 2010 at 12:24 pm

Comments are closed.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close