Domanda

io sono sempre "un'eccezione non gestita di tipo 'System.StackOverflowException' in system.data.dll" nella mia proprietà DataView RowFilter. Non ricevo alcuna traccia dello stack per questo. Così Può uno mi aiuto su questo. Di seguito riportiamo il codice in cui sto ottenendo l'errore nel filterView.

                DataSet metalAttributeDS = LoadItemData();    //loads the static dataset
                DataTable metalDataTable = metalAttributeDS.Tables["FilterTable"];
                DataView metalfilterView = new DataView(metalDataTable);
                metalfilterView.ApplyDefaultSort = true;
                metalfilterView.RowFilter = queryBuilder +
                                            string.Format(
                                                " And AttributeName='Metal' and AttributeValueID in ({0})",
                                                string.Join(",", AttributeValueID.ToArray()));      //forms query condition dynamically.

                var res = from DataRowView rowView in metalfilterView select rowView["ItemID"].ToString();

                int countParam = 0;
                queryBuilder.AppendFormat(" and (");
                foreach (string id in res)
                {
                    countParam++;
                    queryBuilder.AppendFormat(" ItemID = '{0}'", id);
                    if (res.Count() > countParam)
                    {
                        queryBuilder.Append(" Or");
                    }
                }
                queryBuilder.Append(" )");
            }


            DataSet dataSet = LoadItemData();       //loads the static dataset
            DataTable dataTable = dataSet.Tables["FilterTable"];
            DataView filterView = new DataView(dataTable);
            filterView.ApplyDefaultSort = true;

                LogHelper.LogInfo(GetType(), "filterView.RowFilter");
                filterView.RowFilter = queryBuilder.ToString(); //      throws error

Grazie, Mehul Makwana.

È stato utile?

Soluzione 3

Ho ottenuto questo risolto con l'aiuto di Aristos, ma, ho fatto piccole modifiche al Aristos frammento,

        foreach (string id in res)
                {
                    sbTheOr.Append(',');
                    Guid guid = new Guid(id);
                    sbTheOr.AppendFormat("Convert('{0}','System.Guid')",guid);
                }

                if (sbTheOr.Length > 0)
                {
                    // remove the first ,
                    sbTheOr.Remove(0, 1);
                    queryBuilder.AppendFormat(" and ItemID in ({0})",sbTheOr.ToString());
                }

In modo che un'eccezione di overflow dello stack è stato solo a causa della enorme risultato. E hanno trovato nuova cosa attraversavano questo che possiamo utilizzare RowFilter sulla colonna Guid utilizzando Convert (espressione, tipo) sintassi.

Grazie Every1,

Mehul Makwana.

Altri suggerimenti

Forse si crea una linea enorme con o, che non possono gestire ... Se si tenta questo ...?

   StringBuilder sbTheOr = new StringBuilder();

    foreach (string id in res)
    {
        sbTheOr.Append(',');
        sbTheOr.Append(id);
    }


    if (sbTheOr.Length > 0)
    {
        // remove the first ,
        sbTheOr.Remove(0, 1);
        queryBuilder.AppendFormat(" and ItemID IN (" + sbTheOr.ToString() + ")");
    }

Si può solo verificare ciò che viene integrato in 'QueryBuilder'? Penso che ci sia una possibilità di qualche 'e' / 'Or' / parentesi graffa di apertura o chiusura proveniente extra alla fine.

semplificata la soluzione

 StringBuilder sb =new StringBuilder();
 res.ToList().ForEach(x => sb.Append(", " + String.Format("Convert('{0}','System.Guid')", new Guid(x))));
 var output = sb.ToString().Trim(',');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top