English 中文(简体)
如何在数据表中采用多种条件。 C#
原标题:How to apply multiple conditions in Datatable.Select in C#
  • 时间:2024-01-20 01:32:27
  •  标签:
  • c#
  • asp.net

我想对数据表适用多种条件。 选择我如何能够这样做。

Below is the code that I have:

dvOrg.Table.Select("customer_type_id= 64501 ", "sort_column");

Now I want to apply one more condition covered_patient_type= Inpatient . I tried this but it did not work.

dvOrg.Table.Select("customer_type_id= 64501  and covered_patient_type= Inpatient ", "sort_column");

请提供帮助。

提前感谢。

问题回答

守则是正确的,这意味着问题将涉及具体数据表和数据类型。

这一缺陷证明了这一概念,由多个栏目选择,与WHERE条款相似,使用<代码>AND<>/code>,以补充一栏标准。 本《任择议定书》是正确的。

https://dotnetfiddle.net/7cPr5H

dvOrg.Table.Select("customer_type_id= 64501  and covered_patient_type= Inpatient ", "id DESC");

只有当<代码>发现-patient_type在暗中被注入体内时,才进行这项工作。

关于这一数据,我们可以看到,customer_type_id <>/code>是一种隐蔽,但在过滤器中,我们可以期望它是一种扼杀,过滤条件仍然奏效:

[{"id":1623,"customer_type_id":645,"covered_patient_type":"Outpatient","expectation":"filtered out"},
{"id":1624,"customer_type_id":645,"covered_patient_type":"Inpatient","expectation":"filtered out"},
{"id":1625,"customer_type_id":64501,"covered_patient_type":"Outpatient","expectation":"filtered out"},
{"id":1626,"customer_type_id":64501,"covered_patient_type":"Inpatient","expectation":"selected"},
{"id":1627,"customer_type_id":64501,"covered_patient_type":"Outpatient","expectation":"filtered out"},
{"id":1628,"customer_type_id":64501,"covered_patient_type":"Inpatient","expectation":"selected"},
{"id":1629,"customer_type_id":64501,"covered_patient_type":"Outpatient","expectation":"filtered out"}] 
Filter By two columns: customer_type_id= 64501  and covered_patient_type= Inpatient 
ID:1628, expectation:selected, customer_type_id:64501, covered_patient_type:Inpatient
ID:1626, expectation:selected, customer_type_id:64501, covered_patient_type:Inpatient

The common scenario where this isn t straight forward are when covered_patient_type is stored as an integer (or some other type where the value is a reference to another list, or enum and you are resolving the visible value in the view.

在这种情形下,如果(> In Hospital” in view is an enum, itto an int, or 如果In Hospital is a vlaue from a relevant table or otherwise unleated list,解决了与t underlying DataTable dataset所用数值相称的点值。

所有这些都很容易解决,将原始数据输入你原来的职位。 但我希望这一思考进程将有助于你自己探讨这些概念。





相关问题
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!