0

请帮助我如何将下面的 sql 查询转换为 vb.net 中的 Linq 语句

select   distinct PATIENT_DIAGNOSIS_DESCRIPTION, PATIENT_DIAGNOSIS_CODE,
         PATIENT_DIAGNOSIS_ACCOUNT,PATIENT_DIAGNOSES_STATUS 
from     MF_PATIENT_DIAGNOSES 
where    PATIENT_DIAGNOSIS_ACCOUNT= '31'
AND      UPPER(PATIENT_DIAGNOSES_STATUS) <> 'ENTRY ERROR' 
GROUP BY PATIENT_DIAGNOSIS_DESCRIPTION, PATIENT_DIAGNOSIS_CODE, 
         PATIENT_DIAGNOSIS_ACCOUNT,PATIENT_DIAGNOSES_STATUS 
ORDER BY PATIENT_DIAGNOSIS_DESCRIPTION
4

1 回答 1

1

我用 C# 写过,你可以把它转换成 VB

您可以根据列类型更改字段类型,例如 item.Field 到 Field

 var result = (from item in MF_PATIENT_DIAGNOSES.AsEnumerable()
                   where item.Field<int>("PATIENT_DIAGNOSIS_ACCOUNT") == 31 && item.Field<string>("PATIENT_DIAGNOSES_STATUS").ToUpper() != "ENTRY ERROR"
                   orderby item.Field<string>("PATIENT_DIAGNOSIS_DESCRIPTION")
                   select new
                   {
                       PATIENT_DIAGNOSIS_DESCRIPTION = item.Field<string>("PATIENT_DIAGNOSIS_DESCRIPTION"),
                       PATIENT_DIAGNOSIS_CODE = item.Field<string>("PATIENT_DIAGNOSIS_CODE"),
                       PATIENT_DIAGNOSIS_ACCOUNT = item.Field<string>("PATIENT_DIAGNOSIS_ACCOUNT"),
                       PATIENT_DIAGNOSES_STATUS = item.Field<string>("PATIENT_DIAGNOSES_STATUS "),
                   }).Distinct();

我使用这个http://www.developerfusion.com/tools/convert/csharp-to-vb/转换器转换它

Dim result1 = (From item In MF_PATIENT_DIAGNOSES.AsEnumerable() Where item.Field(Of Integer)("PATIENT_DIAGNOSIS_ACCOUNT") = 31 AndAlso item.Field(Of String)("PATIENT_DIAGNOSES_STATUS").ToUpper() <> "ENTRY ERROR"Order By item.Field(Of String)("PATIENT_DIAGNOSIS_DESCRIPTION")New With { _
Key .PATIENT_DIAGNOSIS_DESCRIPTION = item.Field(Of String)("PATIENT_DIAGNOSIS_DESCRIPTION"), _
Key .PATIENT_DIAGNOSIS_CODE = item.Field(Of String)("PATIENT_DIAGNOSIS_CODE"), _
Key .PATIENT_DIAGNOSIS_ACCOUNT = item.Field(Of String)("PATIENT_DIAGNOSIS_ACCOUNT"), _
Key .PATIENT_DIAGNOSES_STATUS = item.Field(Of String)("PATIENT_DIAGNOSES_STATUS ") 
}).Distinct()
于 2012-09-28T06:04:05.670 回答