Asp.net 数据表选择方法
我的数据表中有一个行列表。Asp.net 数据表选择方法,asp.net,sql-server,Asp.net,Sql Server,我的数据表中有一个行列表。 现在,我不希望根据DESC或ASC对行进行优先级排序,而是基于我的变量与行值的一些相似性 例如, 我有如下列的datatable: Name, Location, Age, Sex, Education.. 我已经有了一些偏好,首先看到那些与我的教育和位置相匹配的行,而那些不匹配的行可以在第一行之后 我如何做到这一点? 我尝试用或和LIKE子句设置SELECT语句中的表达式,但似乎没有得到正确的答案 在这里,我不想严格要求我只需要这些值,但我首先需要这些值的首选项设
现在,我不希望根据
DESC
或ASC
对行进行优先级排序,而是基于我的变量与行值的一些相似性
例如,我有如下列的datatable:
Name, Location, Age, Sex, Education..
我已经有了一些偏好,首先看到那些与我的教育和位置相匹配的行,而那些不匹配的行可以在第一行之后
我如何做到这一点?我尝试用
或和LIKE子句设置SELECT语句中的表达式,但似乎没有得到正确的答案
在这里,我不想严格要求我只需要这些值,但我首先需要这些值的首选项设置,其余的可以在后面使用。您可以上传一些您已经尝试过的代码示例吗
像这样试试
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);
您可以使用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'"
然后你必须得到匹配的列,并通过匹配列名称来使用顺序。你能给出表数据值和预期结果的示例吗?@Prabhavith-是的,但我对匹配并不严格。意味着你也需要其他栏目。。我该怎么做?@Tani你必须动态获取列你必须在“%”之间添加一个空格,或者在你的代码中,首先尝试,正如我说的,我不想要ASC
或DESC
,但选择我想首先看到的关键字嗯,好的,我会这样做..然后让你知道
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'"