Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有GUID的DataTable Select()_C#_.net 3.5_Datatable_Guid - Fatal编程技术网

C# 带有GUID的DataTable Select()

C# 带有GUID的DataTable Select(),c#,.net-3.5,datatable,guid,C#,.net 3.5,Datatable,Guid,我试图在运行时从LINQ查询返回的数据表中编译我的treeview。返回的字段包括: NAME=CaseNoteID | ContactDate | ParentNote 类型=Guid |日期时间| Guid ParentNote字段与CaseNoteID列中的条目匹配。Select(筛选器)给我一个运行时错误找不到列[ea8428e4]。字母数字是其中一个GUI的第一部分。当我单步通过我的代码过滤器=“ParentNote=ea8428e4-1274-42e8-a31c-f57dc2f189

我试图在运行时从LINQ查询返回的数据表中编译我的treeview。返回的字段包括:

NAME=CaseNoteID | ContactDate | ParentNote 类型=Guid |日期时间| Guid

ParentNote字段与CaseNoteID列中的条目匹配。Select(筛选器)给我一个运行时错误找不到列[ea8428e4]。字母数字是其中一个GUI的第一部分。当我单步通过我的代码过滤器=
“ParentNote=ea8428e4-1274-42e8-a31c-f57dc2f189a4”

我错过了什么

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

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

尝试用单引号括住GUID:

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

尝试用单引号括住GUID:

var filter = "ParentNote='"+tmpCNoteID+"'";
这应该起作用:

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

                DataRow[] childRows = cNoteDT.Select(filter);
这应该起作用:

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

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

以下是我使用的一种方法:

            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;
这里有一个小小的变化:

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

  filterSql = string.Format(filterSql, Guid.NewGuid().ToString("D"));

以下是我使用的一种方法:

            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;
这里有一个小小的变化:

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

  filterSql = string.Format(filterSql, Guid.NewGuid().ToString("D"));

我知道这是一个旧的线程,但我想添加一个补遗。使用带有Guid的IN运算符(例如,(,等)中的ParentNote)时,将不再接受单引号。在这种情况下,转换方法(由GranadCoder建议)是必要的。(单引号引发了一个异常,关于将Guid与带有“=”运算符的字符串进行比较,我们实际上没有使用“=”运算符。)

详细信息:我继承了一些旧代码,它们以以下格式构建了一个大的筛选字符串:
MyColumn='11111111-2222-3333-4444-555555'或MyColumn='11111111-2222-3333-4444-5555'.


当GUID的数量(因此OR子句的数量)过大时,这会导致堆栈溢出异常。通过将大量OR子句替换为IN子句,我可以毫无例外地设置过滤器。但是使用IN子句意味着必须使用CONVERT方法。

我知道这是一个旧线程,但我想添加一个补遗。使用带有Guid的IN运算符(例如,(,等)中的ParentNote)时,将不再接受单引号。在这种情况下,转换方法(由GranadCoder建议)是必要的。(单引号引发了一个异常,关于将Guid与带有“=”运算符的字符串进行比较,我们实际上没有使用“=”运算符。)

详细信息:我继承了一些旧代码,它们以以下格式构建了一个大的筛选字符串:
MyColumn='11111111-2222-3333-4444-555555'或MyColumn='11111111-2222-3333-4444-5555'.

当GUID的数量(因此OR子句的数量)过大时,这会导致堆栈溢出异常。通过将大量OR子句替换为IN子句,我可以毫无例外地设置过滤器。但是使用IN子句意味着必须使用CONVERT方法