如何使用DataTable.Select()访问具有特殊字符的列? [英] How to access an column with special characters using DataTable.Select()?

查看:574
本文介绍了如何使用DataTable.Select()访问具有特殊字符的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataTable ,列如#个学生,并希望以降序排序。这是我的代码:

I have a DataTable with column such as # of Students and would like to sort by this in descending order. Here is my code:

...
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");

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

How can I access this column if has special characters in its name?

推荐答案

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

You should use [] brackets, like this :

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

这篇关于如何使用DataTable.Select()访问具有特殊字符的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆