English 中文(简体)
数据选择方法
原标题:DataTable Select method

I have a list of rows in my datatable.
Now I wish to prioritize the rows not according to DESC or ASC but based on few similarities of my variables with the row values.

For example,
I have datatable with columns as below:

Name, Location, Age, Sex, Education..

而且,我已经有一些倾向,即看到那些与我教育和地点相匹配的头几行,以及那些与他们相匹配的行子,可以排在第一行之后。

How do I accomplish this?
I tried setting expression in SELECT statement with OR and LIKE clause but I didn t seem to be getting the right answer.

DataRow[]  row = ds.Tables[0].Select("Affiliations LIKE  %" + ftr2 + "% OR Loc_city LIKE  %" + city1 + "% OR Edu_Hist LIKE  %" + ftr + "% OR Work_Hist LIKE  %" + ftr1 + "%  OR Priority= true ");

这里,一意是严格地说,只希望这些价值观,而一味希望这些价值观首先得到支持的偏好环境。

问题回答

您能上载一些已尝试过的密码样本?

尝试

DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > #1/1/00#";
DataRow[] foundRows;

// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression);

you can use the Union select statement, first select the matched rows and than the unmatched like this:

   string selectQuery="select Affiliations LIKE  %" + ftr2 +
                       "% OR Loc_city LIKE  %" + city1 + 
                       "% OR Edu_Hist LIKE  %" + ftr + 
                       "% OR Work_Hist LIKE  %" + ftr1 + 
                       "%  OR Priority= true  
                           union select Affiliations not LIKE  %" + ftr2 + 
                       "% and Loc_city not LIKE  %" + city1 + 
                       "% and Edu_Hist not LIKE  %" + ftr + 
                       "% and Work_Hist not LIKE  %" + ftr1 + 
                       "%  and Priority != true "




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签