在asp.net中重新获取DataTable.Select(); [英] Reagrd DataTable.Select() in asp.net;
问题描述
DataTable dtGetAll = new DataTable();
LoanClass lcls = new LoanClass();
dtGetAll = lcls.Get_AllLoan();
DataTable dtEmpRecord = new DataTable();
DataRow[] drEmp = dtGetAll.Select("empName like '" + txtNameNumber.Text+"%'");
假设当我在txtNameNumber.Text中输入``SHEELA''并尝试filter.its返回0行.但是在dataTable中dtGetAll包含包含该名称的行.
我现在该怎么办...
suppose when i enter ''SHEELA'' in the txtNameNumber.Text and try filter.its return 0 rows.but in the dataTable dtGetAll has row containing such name.
what will i have to do now...
推荐答案
它返回0行.但是在dataTable dtGetAll中有包含该名称的行.
假设
,上面的代码看起来不错 1.区分大小写已关闭或区分大小写 [ ^ ](如果打开)值是确切的方法
2.有一列名为"empName"的
试试这个:
its return 0 rows.but in the dataTable dtGetAll has row containing such name.
Above code looks fine, assuming
1. Case sensitivity is turned off or casesensitivity[^] if turned on then the value is exact macth
2. There is a column with name ''empName''
Try this:
DataRow[] drEmp = dtGetAll.Select("[empName] like '" + txtNameNumber.Text.Trim() + "%'");
替代:
Select
方法的问题在于,它没有按预期方式返回已过滤的表对象-它返回了DataRow对象的数组.因此,您不能直接将此数组绑定到DataGrid或其他数据绑定控件.而是尝试DataView
:
Alternative:
The problem with the Select
method is that it does not return a filtered table object as expected - it returns an array of DataRow objects. Thus you can not directly bind this array to a DataGrid or other data bound controls. Instead try DataView
:
dtGetAll.DefaultView.RowFilter = "[empName] LIKE '" + txtNameNumber.Text + "%'";
DataTable dtOutput = dtGetAll.DefaultView.ToTable();
在filter事件中,只需使用dataview过滤数据,然后将过滤后的dataview用作网格的数据源.
若要了解更多信息,请阅读此处: MSDN:DataView.RowFilter属性 [^ ]
On the filter event, just filter the data using a dataview and then use the filtered dataview as the datasource of your grid.
To know more of it, read here: MSDN: DataView.RowFilter Property[^]
这篇关于在asp.net中重新获取DataTable.Select();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!