c# - Using 'SUBSTRING(expression, startIndex, length)' with BindingSource on DataColumn -


i trying filter numeric string matching start of source string , length of search string.

all filtered columns strings. words, there 1 column has values 001302:alt#. underlying data source sucks, cannot change structure. numbers grouped based on left-hand values (i.e. 050110 , 050534 both related client(05), 052123 related client(05) invoices(2)). users want able search data in datagridview , filter column group (i.e. enter 05 , see starts 05, or 052 , see 052000-052999)

i generating filter string , setting filter property on bindingsource using dataset datasource , table datamember. rest of filtering works, problem having numeric filter. when set bindingsource.filter property, throws argumentoutofrange exception.

an unhandled exception of type 'system.argumentoutofrangeexception' occurred in system.data.dll additional information: substring() argument out of range.

i thought might firing against empty row, or 1 had few digits, firing 1 character. therefore, length argument should valid, still throwing exception.

bool firstcolumn = true; foreach (datacolumn column in filteredcolumns.keys) {     if (filteredcolumns[column])     {         if (!firstcolumn) fieldfilter.append(") or ("); else firstcolumn = false;          int numericfilter;         if (int.tryparse(filterword, out numericfilter))         {             fieldfilter.append(string.format("substring({0}, 0, {2}) = {1}", column.columnname, filterword, filterword.length));         }         else             {             fieldfilter.append(string.format("{0} '%{1}%'", column.columnname, filterword));             }     } } 

i sure missing stupid. thank in advance pointing out error(s)!

never mind. making assumption datacolumn expression substring behaved same string.substring. substring expression 1 based index, whereas string.substring method starts it's index @ 0. should have checked first, instead tried running brick wall hours...

thanks anyways guys!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -