既不是 DataColumn 也不是 DataRelation - asp.net 错误

Neither a DataColumn nor a DataRelation - asp.net error

我收到这个错误:

banner_flag is neither a DataColumn nor a DataRelation for table temp

搜索后,错误显然出现了,因为我正在引用 banner_flag,但它不存在,但我已在与 intra_user 相同的所有位置声明它(如一个例子)。

下面是我的代码,非常感谢任何帮助。谢谢!:

Dim reason As String = ""
Dim banner_action As String = ""
Dim esr_link As String = ""
Dim seen_message AS String = ""
Dim last_updated AS String = ""
Dim daysSinceUpdated As Integer
Dim intra_user As String = ""
Dim banner_flag As String = ""

Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
    Dim sc As Web.HttpContext = Web.HttpContext.Current
    Dim updatePeriod As Integer = 90
    Dim strConn As String = getStrConn(sc)
    Dim rst As DataView
    Dim strsql, last_updated, email_address As String
    Dim update_required As String = ""

    ' - Really don't know what this is for... so I have commented it out.
    ' - Response.Write("<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />hello no details")

    ' Check users last update to their email address
       strsql = "select last_updated, email, esr_link, intra_user, banner_action, seen_message from user_group where id = " & Session("u_id") & " AND (esr_link <> 5)"
       rst = GetDefaultView(strsql, strConn)

       If (rst.count > 0) Then
       ' Get details for new banner check for launching windows at startup
       If Not IsDBNull(rst(0)("banner_action")) Then
         banner_action = rst(0)("banner_action").ToString
       Else 
         banner_action = ""
       End If

       ' Get details for seen message
       If Not IsDBNull(rst(0)("seen_message")) Then
         seen_message = rst(0)("seen_message").ToString
       Else  
         seen_message = ""
       End If

       ' Gets banner_flag value
       If Not IsDBNull(rst(0)("banner_flag")) Then
         banner_flag = rst(0)("banner_flag").ToString
       Else 
         banner_flag = ""
       End If



       ' Gets the ESR link value to check if the New User code needs to run
       If Not IsDBNull(rst(0)("esr_link")) Then
         esr_link = rst(0)("esr_link").ToString
       Else 
         esr_link = ""
       End If


       ' Gets the intra_user value
       If Not IsDBNull(rst(0)("intra_user")) Then
         intra_user = rst(0)("intra_user").ToString
       Else 
         intra_user = ""
       End If



        ' Grab users last_updated value if available
            If Not IsDBNull(rst(0)("last_updated")) Then
               last_updated = rst(0)("last_updated").ToString
            Else 
               last_updated = ""
        End If

        ' Grab users email address if available
            If Not IsDBNull(rst(0)("email")) Then
               email_address = rst(0)("email").ToString
       email_address = Replace(email_address, "'", "")

            Else
               email_address = ""
        End If

            'Checks the email address to see if it is valid
            If email_address <> "" Then
                If IsEmailValid(email_address) = False Then
                    update_required = "true"
                    reason = "Your current Email address is invalid please     update it." & vbCrLf
                End If
            Else
                update_required = "true"
                reason = "You have not entered a current Email address please add one." & vbCrLf
        End If

            'If it not empty then compare
            If last_updated <> "" Then
                last_updated = CDate(last_updated)
                daysSinceUpdated = DateDiff("d", last_updated, Now())
                If daysSinceUpdated > updatePeriod Then
                    update_required = "true"
                    reason &= "Your details have expired please check them to ensure they are up-to-date" & vbCrLf
                End If
                'If it empty then needs updating...
            Else
                update_required = "true"
                reason = "Your details have expired please check them to ensure they are up-to-date" & vbCrLf
        End If

        rst.Dispose()
        rst = Nothing
        Session("checked_details") = "true"

        If update_required = "true" Then
            reason = Server.UrlEncode(reason)
       'response.write(reason)

            'Response.Write("<scr" & "ipt language='javascript'>findTop().submitURL('/sorce/app_centre/launch_form.aspx?fhandle=User_Details_Amendment&elemid=" & Session("u_id") & "&reason=" & reason & "');</scr" & "ipt>")

        End If

    Else

        'Response.Write("<br /><br /><br /><br /><br /><br />hello details")
        'Response.Write("<scr" & "ipt language='javascript'>findTop().submitURL('/sorce/app_centre/launch_form.aspx?fhandle=User_Details_Amendment&elemid=" & Session("u_id") & "&reason=" & reason & "');</scr" & "ipt>")


    End If
End Sub

Function IsEmailValid(ByVal strEmail As String) As Boolean
    Dim strArray() As String
    Dim strItem As String
    Dim i As Integer
    Dim c As String
    Dim blnIsItValid As Boolean

    ' assume the email address is correct  
    blnIsItValid = True

    ' split the email address in two parts: name@domain.ext 
    strArray = Split(strEmail, "@")

    ' if there are more or less than two parts  
    If UBound(strArray) <> 1 Then
        blnIsItValid = False
        IsEmailValid = blnIsItValid
        Exit Function
    End If

    ' check each part 
    For Each strItem In strArray
        ' no part can be void 
        If Len(strItem) <= 0 Then
            blnIsItValid = False
            IsEmailValid = blnIsItValid
            Exit Function
        End If

        ' check each character of the part 
        ' only following "abcdefghijklmnopqrstuvwxyz_-." 
        ' characters and the ten digits are allowed 
        For i = 1 To Len(strItem)
            c = LCase(Mid(strItem, i, 1))
            ' if there is an illegal character in the part 
            If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then
                blnIsItValid = False
                IsEmailValid = blnIsItValid
                Exit Function
            End If
        Next

        ' the first and the last character in the part cannot be . (dot) 
        If Left(strItem, 1) = "." Or Right(strItem, 1) = "." Then
            blnIsItValid = False
            IsEmailValid = blnIsItValid
            Exit Function
        End If
    Next

    ' the second part (domain.ext) must contain a . (dot) 
    If InStr(strArray(1), ".") <= 0 Then
        blnIsItValid = False
        IsEmailValid = blnIsItValid
        Exit Function
    End If

    ' check the length oh the extension  
    i = Len(strArray(1)) - InStrRev(strArray(1), ".")
    ' the length of the extension can be only 2, 3, or 4 
    ' to cover the new "info" extension 
    If i <> 2 And i <> 3 And i <> 4 Then
        blnIsItValid = False
        IsEmailValid = blnIsItValid
        Exit Function
    End If

    ' after . (dot) cannot follow a . (dot) 
    If InStr(strEmail, "..") > 0 Then
        blnIsItValid = False
        IsEmailValid = blnIsItValid
        Exit Function
    End If

    ' finally it's OK  
    IsEmailValid = blnIsItValid

End Function

您的sql声明是:

select last_updated, email, esr_link, intra_user, banner_action, seen_message from user_group where ...

因此 intra_user 的返回 DataView 中会有一个列,它在 sql select 中存在,但 banner_flag 中不存在.