Question

I am trying to boild my treeview at runtime from a DataTable that is returned from a LINQ query. The Fields returned are:

NAME = CaseNoteID | ContactDate | ParentNote TYPE = Guid | DateTime | Guid

The ParentNote field matches a entry in the CaseNoteID column. The Select(filter) is giving me a runtime error of Cannot find column [ea8428e4]. That alphanumeric is the first section of one of the Guids. When I step thru my code filter = "ParentNote=ea8428e4-1274-42e8-a31c-f57dc2f189a4"

What am I missing?

var tmpCNoteID = dr["CaseNoteID"].ToString();
                var filter = "ParentNote="+tmpCNoteID;

                DataRow[] childRows = cNoteDT.Select(filter);
Was it helpful?

Solution

Try enclosing the GUID with single quotes:

var filter = "ParentNote='"+tmpCNoteID+"'";

OTHER TIPS

this should work :

   var tmpCNoteID = dr["CaseNoteID"].ToString();
                var filter = "ParentNote=\""+tmpCNoteID+"\"";

                DataRow[] childRows = cNoteDT.Select(filter);

I know this is an old thread, but I wanted to add an addendum to it. When using the IN operator with a Guid (ex: ParentNote IN ( , , etc. ) ) then single quotes are no longer accepted. In that case, the CONVERT method (suggested by granadaCoder) is necessary. (Single quotes raise an exception about comparing a Guid to a string with the '=' operator... which we actually aren't using.)

Details: I inherited some legacy code that built a large filter string in the format: MyColumn = '11111111-2222-3333-4444-555555555555' OR MyColumn = '11111111-2222-3333-4444-555555555555' ....

When the number of guids (and, therefore the number of OR clauses) got to be too large, this caused a stack overflow exception. By replacing the numerous OR clauses with an IN clause, I was able to set the filter without an exception. But using an IN clause means having to use the CONVERT approach.

Here is one method I use:

            MyStrongDataSet ds = new MyStrongDataSet();
            Guid myUuid = new Guid("11111111-2222-3333-4444-555555555555");

            System.Data.DataRow[] rows = ds.MyStrongTable.Select("MyGuidProperty = (CONVERT('" + myUuid.ToString("N") + "', 'System.Guid'))");


            //Fish out a single row if need be and cast to a strong row
            if (null != rows)
            {
                if (rows.Length > 0)
                {
                    MyStrongDataSet.MyStrongTableRow returnRow = rows[0] as MyStrongDataSet.MyStrongTableRow;
                    return returnRow;

                }
            }
            return null;

Here is a slight variation:

  string filterSql = "MyGuidProperty ='{0}'";

  filterSql = string.Format(filterSql, Guid.NewGuid().ToString("D"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top