0

我有一个DataTablewith 列,例如# of Students并且想按降序排序。这是我的代码:

...
dt.Columns.Add(new DataColumn("# of Students", typeof(string)));

// do some stuff... add records etc.

// A runtime error occurs here: "Cannot find column '# of Students'"
var rows = dt.Select("","'# of Students' desc");

// this is just fine.
rows = dt.Select("","# of Students");

如果名称中有特殊字符,如何访问此列?

4

2 回答 2

3

您可以同时使用 [] 或 `` 语法。以下两个片段都是正确的:

var rows = dt.Select("","`# of Students` desc");

var rows = dt.Select("","[# of Students] desc");
于 2012-04-10T00:33:15.050 回答
2

您应该使用 [] 括号,如下所示:

var rows = dt.Select("","[# of Students] desc");
于 2012-04-10T00:26:56.923 回答