2010-05-17 2 views
0

LINQ 결과를 통해 반복 할 수있는 코드가 있지만 작동하지 않는 것 같습니다.LINQ 결과를 통해 루프하는 방법 (VB.NET)

은 여기 여기에 코드를

Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest 
     ''# the page contenttype is plain text' 
     HttpContext.Current.Response.ContentType = "text/plain" 

     ''# store the querystring as a variable' 
     Dim qs As Nullable(Of Integer) = Integer.TryParse(HttpContext.Current.Request.QueryString("ID"), Nothing) 

     ''# use the RegionsDataContext' 
     Using RegionDC As New DAL.RegionsDataContext 

      ''# create a (q)uery variable' 
      Dim q As Object 

      ''# if the querystring PID is not blank' 
      ''# then we want to return results based on the PID' 
      If Not qs Is Nothing Then 
       ''# that fit within the Parent ID' 
       q = (From r In RegionDC.bt_Regions _ 
         Where r.PID = qs _ 
         Select r.Region).ToArray 

       ''# now we loop through the array' 
       ''# and write out the ressults' 
       For Each item As DAL.bt_Region In q 
        HttpContext.Current.Response.Write(item.Region & vbCrLf) 
       Next 

      End If 



     End Using 
    End Sub 

있어 오류입니다

Public member 'Region' on type 'String' not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMemberException: Public member 'Region' on type 'String' not found.

Source Error:

Line 33: ' and write out the ressults Line 34:
For Each item In q Line 35:
HttpContext.Current.Response.Write(item.Region & vbCrLf) Line 36:
Next Line 37:

Source File: E:\Projects\businesstrader\App_Code\Handlers\RegionsAutoComplete.vb Line: 35

Stack Trace:

[MissingMemberException: Public member 'Region' on type 'String' not found.] Microsoft.VisualBasic.CompilerServices.Container.GetMembers(String& MemberName, Boolean ReportErrors) +509081 Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) +222 BT.Handlers.RegionsAutoComplete.ProcessRequest(HttpContext context) in E:\Projects\businesstrader\App_Code\Handlers\RegionsAutoComplete.vb:35 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

사람이 내가 잘못 뭘하는지 말해 줄래?

답변

2

속성에 저장된 개체의 유형이 String이므로 액세스하려고 시도한 구성원이 이라는 오류 메시지가 표시됩니다.

DAL.bt_Regions의 유형이 무엇인지 다시 확인합니다. 일부 클래스를 반환한다고 가정하고 있지만 문자열 집합 (아마도 지역 이름일까요?)을 반환하는 것처럼 보입니다. 가 포함 된 내용을 확인하려면, 당신은 다음과 같이 코드를 수정할 수 있습니다 : 나는 또한 컴파일시 오류의 종류를 확인하도록 컴파일러에 지시 할 것 Option Strict On 옵션을 (가능한 경우), 추가하려고 할

HttpContext.Current.Response.Write(item & vbCrLf) // to print the string 

.

+0

아 답니다. 데이터베이스에서 하나의 레코드 (문자열) 만 선택하기 때문에 "item"을 사용했습니다. –

관련 문제