DataTable的一些特殊用法:Select
/**//*
* 补充一下,还可以利用DataView来达到检索的目的。
*/
DataTable dataSource = new DataTable();
DataView dv = dataSource.DefaultView;
dv.RowFilter = "columnA = 'abc'";
//1.过滤后直接获取DataTable
DataTable newTable1 = dv.ToTable();
//2.设置新DataTable的TableName
DataTable newTable2 = dv.ToTable("NewTableName");
//3.设置新表是否过滤重复项,拥有的列的列名以及出现的顺序
//即可以设置新表的字段。但是字段名肯定是老表dataSource中拥有的。
DataTable newTable3 =
dv.ToTable(true, new string[] { "columnA,columnF,columnC" });
//4.综合了2.3两点。
DataTable newTable4 =
dv.ToTable("NewTableName", true, new string[] { "columnA,columnF,columnC" });
简化,利用 DataView过滤
DataView dv = this.dtPerson.DefaultView; //设置一个视图过滤
dv.RowFilter = "employee_dept_id = " + departId;
this.lstSource.DataSource = dv;
this.lstSource.DisplayMember = "employee_name";
this.lstSource.ValueMember = "id";
this.dvPendingNode.RowFilter = "(node_end_time is null or node_end_time > '2009-6-10 17:55:13')";
this.dvPendingNode.RowFilter += "and degree_name in ('', '进行', '暂停', '搁置') ";
1. 我在一个winform程序里用DataView的RowFilter筛选时用两个下划线代表两个字符,但是怎么筛选不出来的?
http://topic.csdn.net/t/20040814/04/3273316.html
Q:
我在一个winform程序里用DataView的RowFilter筛选时用两个下划线代表两个个字符,如:
dv.RowFilter="PID LIKE '"+str+"-__",这样的筛选语句在SQL企业管理器里执行是能正确筛选到记录的,但是为什么在这里就一个都筛选不出来?是不是这里要用别的符号来代表一个字符啊。
A:
"_" is probably very sql server specific, classes in System.Data is supposed to be DBMS independent, you can try to use
ABC LIKE 'abc*' AND LEN(ABC)=5
2. ListBox 多项选择(DataRowView)
for (int i = 0; i < this.lstSource.SelectedItems.Count; i++)
{
DataRowView row = this.lstSource.SelectedItems[i] as DataRowView;
int id = Int32.Parse(row["id"].ToString());
string employee = String.Format("{0}<{1}>", row["employee_name"], row["dept_name"]);
//数据填充
if (!this.idList.Contains(id))
{
this.idList.Add(id);
this.valueList.Add(employee);
}
System.Windows.Forms.ListBox.SelectedIndexCollection indexes = this.lstTarget.SelectedIndices;
for (int i = indexes.Count - 1; i >= 0; i--)
{
this.idList.RemoveAt(indexes[i]);
this.valueList.RemoveAt(indexes[i]);
}
posted on 2010-04-22 12:35
黄小二 阅读(1641)
评论(0) 编辑 收藏 所属分类:
C#