views:

76

answers:

3

Hi All,

I am getting "An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll" in my DataView rowfilter property. I'm not getting any stack trace for that. So can any one help me on that. Please find below the code where i'm getting the error in 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

Thanks, Mehul Makwana.

+1  A: 

Maybe you create a huge line with or, that can not handle... If you try this... ?

   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() + ")");
    }
Aristos
yes res contains a huge result set. so that can be problem?. well ill try with the snippet what you gave and let you know. Thanks for help. :)
mehul9595
hey friend i tried what you suggested me. Its giving "Missing operand after 'dbb' operator" error now.
mehul9595
In stack trace it tells me "Cannot perform '=' operation on System.Guid and System.String."
mehul9595
A: 

Can you just verify what is being built into 'queryBuilder' ? I think there is a possibility of some 'And'/'Or'/open or close brace coming extra at the end.

Siva Gopal
i checked my query builder value. It contains the query perfectly formated. :(
mehul9595
A: 

Hey All,

I got this fixed by help of Aristos but, i did little modifications to Aristos snippet,

        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());
                }

So that stack overflow exception was just because of huge result. And have found new thing accross this that we can use RowFilter on Guid column using Convert(expression, type) syntax.

Thanks Every1,

Mehul Makwana.

mehul9595