Problem with escape sequences

2

The following method corresponds to the EditValueChanged event of a combobox that has gridview filters stored. I use this event so that when selecting the index, I can get the "where" that corresponds to the SQL query that has this filter stored.

private void LookUpCuentas_EditValueChanged(object sender, EventArgs e)
    {
        if (LookUpCuentas.ItemIndex == 0)
        {
            gridView2.ClearColumnsFilter();
        }
        else
        {
            MemoryStream tempMem = new MemoryStream((LookUpCuentas.GetSelectedDataRow() as Filtro).FiltroFile);
            Extensions.RestoreLayoutFromXmlEx(gridView2, provider, tempMem);

            DataView dv = new DataView();
            CriteriaOperator op = gridView2.ActiveFilterCriteria;
            string filterString = CriteriaToWhereClauseHelper.GetMsSqlWhere(op);
            dv.RowFilter = filterString;
            MessageBox.Show(dv.RowFilter);
        }
        gridCuentas.Focus();
    }

In the method I create a DataView (dv) and a CriteriaOperator (op) that stores the filter that I select from the combo (for example I select the Entre Rios filter, then op stores: Provincia.NombreProvincia = 'Entre Rios') . Then with CriteriaToWhereClauseHelper.GetMsSqlWhere(op) I get the filter where and in filterString I am stored "(\"Provincia.NombreProvincia\" = N'ENTRE RIOS')" which is what I need to work on later, but here is where the syntax exception throws me:

  

Additional information: Can not interpret token '"' at position 28.

And in the detail of the exception he tells me that he does not interpret \ "

  

{"Can not interpret token '\"' at position 28. "}

I tried to modify the escape sequence with the following code:

filterString.Replace("\"", "\\"").Trim();

and with

filterString.Replace(@"""", @"\""").Trim(); 

but the error remains the same.

    
asked by Pablo Matias 04.10.2017 в 17:11
source

1 answer

0

With the help of @Pikoh I was able to solve it, it was not necessary to work with the escape sequences, I simply passed the result of CriteriaOperator to the dv.RowFilter. Then the method is as follows:

private void LookUpCuentas_EditValueChanged(object sender, EventArgs e)
    {
        if (LookUpCuentas.ItemIndex == 0)
        {
            gridView2.ClearColumnsFilter();
        }
        else
        {
            MemoryStream tempMem = new MemoryStream((LookUpCuentas.GetSelectedDataRow() as Filtro).FiltroFile);
            Extensions.RestoreLayoutFromXmlEx(gridView2, provider, tempMem);

            DataView dv = new DataView();
            CriteriaOperator op = gridView2.ActiveFilterCriteria;
            dv.RowFilter = op.ToString();

        }
        gridCuentas.Focus();
    }
    
answered by 04.10.2017 / 18:35
source