0

我的数据表中有一个行列表。
现在,我希望不根据DESCASC根据我的变量与行值的一些相似性来对行进行优先级排序。

例如,
我有如下列的数据表:

Name, Location, Age, Sex, Education..

而且我已经有一些偏好,即首先查看与我的教育和位置匹配的那些行,而那些不匹配的行可以在第一行之后。

我该如何做到这一点?
我尝试在SELECT statementwith中设置表达式ORLIKE clause但我似乎没有得到正确的答案。

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

在这里,我不想严格地说我只想要这些值,而是我首先想要这些值的偏好设置,其余的可以在它后面。

4

2 回答 2

0

您可以使用 Union select 语句,首先选择匹配的行,然后选择不匹配的行,如下所示:

   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'"
于 2012-04-04T10:19:45.523 回答
0

您可以上传一些您已经尝试过的代码示例吗?

试试这样

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

http://msdn.microsoft.com/en-us/library/zk13kdh0%28v=vs.71%29.aspx

于 2012-04-04T10:04:44.577 回答