使用 MultiView 的代码因 ASP.NET 向导而失败

发布于 2024-08-26 19:33:50 字数 5370 浏览 15 评论 0原文

我最初创建了一个通过在多视图中的视图之间转换而发生的过程,并且效果很好。现在,我已将相同的代码移至 ASP.NET 向导中,但它在第二步中不断抛出错误。错误是: 方法“System.Object AndObject(System.Object, System.Object)”不支持对 SQL 的转换。 您知道为什么将代码移入向导时会发生这种情况吗?我确信这很愚蠢,但我现在已经检查了代码 3-4 次,它在操作上看起来是相同的。 这是代码: ' 确保我们有 .NET Framework 的 LDAP 部分可用。 Imports System.DirectoryServices ' 允许我们与 LDAP 交互。 Imports System.Data.Linq.SqlClient ' 允许我们使用 LINQ SQL 方法。

部分公开课建设 继承System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' ******* Grab the LDAP info. for current user.
    Dim ID As FormsIdentity = DirectCast(User.Identity, FormsIdentity)
    Dim ticket As FormsAuthenticationTicket = ID.Ticket
    Dim adDirectory As New DirectoryEntry("LDAP://OU=[info],DC=[info],DC=[info],DC=[info]")
    ' We need to strip off @email.address from the ticket name, so we'll use substring to grab the first 
    ' five characters.
    Dim adTicketID As String = ticket.Name.Substring(0, 5)
    Dim adEmployeeID As String
    adEmployeeID = adDirectory.Children.Find("CN=" & adTicketID).Properties("employeeID").Value

    ' ******* Lets make sure they have signed the housing contract and the community covenant.
    Dim dbContractSigs As New pcRoomOccupantsDataContext
    Dim pcContractSigs = From p In dbContractSigs.webContractSigs _
                         Where p.people_id = adEmployeeID _
                         Select p.res_contract, p.comm_life
    If pcContractSigs.Count.Equals(0) Then
        Response.Redirect("signcontract.aspx")
    Else
        Dim cs As String = pcContractSigs.First.res_contract.ToString
        Dim cos As String = pcContractSigs.First.comm_life.ToString
        If cs = "Y" And cos = "Y" Then
            ' We don't need to do anything.
            ' We use the else statement b/c there are multiple conditions that could occur besides "N"
            ' that would cause us to redirect to the signature page, whereas there is only one valid response - "Y".
        Else
            ' Redirect the individual to our contracts page.
            Response.Redirect("signcontract.aspx")
        End If
    End If

    ' ******* Now lets find out what gender that individual is.
    Dim dbIndividual As New pcPeopleDataContext
    Dim pcIndividual = From p In dbIndividual.PEOPLEs _
                       Join d In dbIndividual.DEMOGRAPHICs On p.PEOPLE_CODE_ID Equals d.PEOPLE_CODE_ID _
                       Where p.PEOPLE_ID = adEmployeeID _
                       Select p, d
    ' Make a session variable that will carry with the user throughout the session delineating gender.
    Session("sgender") = pcIndividual.First.d.GENDER.ToString
    ' Debug Code.
    ' Put a stop at end sub to get these values.
    ' Response.Write(adEmployeeID)

End Sub
Sub LinqDataSource1_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' Lets get a list of the dorms that are available for user's gender.
    Dim pcDorms As New pcDormsDataContext
    Dim selectedDorms = (From sd In pcDorms.PBU_WEB_DORMs _
                    Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                    Select sd.dorm_building).Distinct()
    e.Result = selectedDorms
End Sub
Public Sub Button_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
    ' ******** Lets pass on the results of our query in LinqDataSource1_Selecting.
    Session("sdorm") = RTrim(e.CommandName)

    ' ******** Debug code.
    ' Response.Write(sDorm)
End Sub
Sub LinqDataSource2_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' ******** Get a list of rooms available in the dorm for user's gender.
    Dim pcDorms As New pcDormsDataContext
    Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                        Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                        And sd.dorm_building = CStr(Session("sdorm")) _
                        Select sd.dorm_room)
    e.Result = selectedDorm
End Sub
Public Sub Button2_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
    ' ******** Lets pass on the results of our query in LinqDataSource2_Selecting.
    Session("sroom") = RTrim(e.CommandName)
End Sub
Sub LinqDataSource3_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' ******** Grabs the individuals currently listed as residing in this room and displays them. Note the use of SqlMethods.Like 
    ' for dorm_building, this is due to legacy issues where dorms sometimes have leading or trailing blank spaces. We could have 
    ' also used Trim.
    Dim pcOccupants As New pcRoomOccupantsDataContext
    Dim roomOccupants = (From ro In pcOccupants.webResidents _
                       Where SqlMethods.Like(ro.dorm_building, "%" & CStr(Session("sdorm")) & "%") _
                        And ro.dorm_room = CStr(Session("sroom")) _
                      Select ro.person_name)
    e.Result = roomOccupants

    ' ******** Debug code.
    'Response.Write(CStr(Session("sdorm")))
    'Response.Write(CStr(Session("sroom")))
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
    ' ******** Reserve the room for a student.
End Sub

结束类

I originally created a process that occurred by transitioning between views in a multiview and it worked fine. Now, I've moved this same code into a ASP.NET Wizard and it keeps throwing an error at the second step. The error is:
Method 'System.Object AndObject(System.Object, System.Object)' has no supported translation to SQL.
Any ideas why this would occur when moving the code into the wizard? I'm sure its something stupid, but I've checked over the code 3-4 times now and it appears identical operationally.
Here is the code:
' Make sure we have the LDAP portion of the .NET Framework available.
Imports System.DirectoryServices ' Allows us to interface with LDAP.
Imports System.Data.Linq.SqlClient ' Allows us to use LINQ SQL Methods.

Partial Public Class buildit
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' ******* Grab the LDAP info. for current user.
    Dim ID As FormsIdentity = DirectCast(User.Identity, FormsIdentity)
    Dim ticket As FormsAuthenticationTicket = ID.Ticket
    Dim adDirectory As New DirectoryEntry("LDAP://OU=[info],DC=[info],DC=[info],DC=[info]")
    ' We need to strip off @email.address from the ticket name, so we'll use substring to grab the first 
    ' five characters.
    Dim adTicketID As String = ticket.Name.Substring(0, 5)
    Dim adEmployeeID As String
    adEmployeeID = adDirectory.Children.Find("CN=" & adTicketID).Properties("employeeID").Value

    ' ******* Lets make sure they have signed the housing contract and the community covenant.
    Dim dbContractSigs As New pcRoomOccupantsDataContext
    Dim pcContractSigs = From p In dbContractSigs.webContractSigs _
                         Where p.people_id = adEmployeeID _
                         Select p.res_contract, p.comm_life
    If pcContractSigs.Count.Equals(0) Then
        Response.Redirect("signcontract.aspx")
    Else
        Dim cs As String = pcContractSigs.First.res_contract.ToString
        Dim cos As String = pcContractSigs.First.comm_life.ToString
        If cs = "Y" And cos = "Y" Then
            ' We don't need to do anything.
            ' We use the else statement b/c there are multiple conditions that could occur besides "N"
            ' that would cause us to redirect to the signature page, whereas there is only one valid response - "Y".
        Else
            ' Redirect the individual to our contracts page.
            Response.Redirect("signcontract.aspx")
        End If
    End If

    ' ******* Now lets find out what gender that individual is.
    Dim dbIndividual As New pcPeopleDataContext
    Dim pcIndividual = From p In dbIndividual.PEOPLEs _
                       Join d In dbIndividual.DEMOGRAPHICs On p.PEOPLE_CODE_ID Equals d.PEOPLE_CODE_ID _
                       Where p.PEOPLE_ID = adEmployeeID _
                       Select p, d
    ' Make a session variable that will carry with the user throughout the session delineating gender.
    Session("sgender") = pcIndividual.First.d.GENDER.ToString
    ' Debug Code.
    ' Put a stop at end sub to get these values.
    ' Response.Write(adEmployeeID)

End Sub
Sub LinqDataSource1_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' Lets get a list of the dorms that are available for user's gender.
    Dim pcDorms As New pcDormsDataContext
    Dim selectedDorms = (From sd In pcDorms.PBU_WEB_DORMs _
                    Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                    Select sd.dorm_building).Distinct()
    e.Result = selectedDorms
End Sub
Public Sub Button_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
    ' ******** Lets pass on the results of our query in LinqDataSource1_Selecting.
    Session("sdorm") = RTrim(e.CommandName)

    ' ******** Debug code.
    ' Response.Write(sDorm)
End Sub
Sub LinqDataSource2_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' ******** Get a list of rooms available in the dorm for user's gender.
    Dim pcDorms As New pcDormsDataContext
    Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                        Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                        And sd.dorm_building = CStr(Session("sdorm")) _
                        Select sd.dorm_room)
    e.Result = selectedDorm
End Sub
Public Sub Button2_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
    ' ******** Lets pass on the results of our query in LinqDataSource2_Selecting.
    Session("sroom") = RTrim(e.CommandName)
End Sub
Sub LinqDataSource3_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
    ' ******** Grabs the individuals currently listed as residing in this room and displays them. Note the use of SqlMethods.Like 
    ' for dorm_building, this is due to legacy issues where dorms sometimes have leading or trailing blank spaces. We could have 
    ' also used Trim.
    Dim pcOccupants As New pcRoomOccupantsDataContext
    Dim roomOccupants = (From ro In pcOccupants.webResidents _
                       Where SqlMethods.Like(ro.dorm_building, "%" & CStr(Session("sdorm")) & "%") _
                        And ro.dorm_room = CStr(Session("sroom")) _
                      Select ro.person_name)
    e.Result = roomOccupants

    ' ******** Debug code.
    'Response.Write(CStr(Session("sdorm")))
    'Response.Write(CStr(Session("sroom")))
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
    ' ******** Reserve the room for a student.
End Sub

End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

握住你手 2024-09-02 19:33:50

我的旧代码如下所示:

Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                            Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                            And sd.dorm_building = Session("sdorm").ToString _
                            Select sd.dorm_room)

并且不起作用(但在使用多视图时确实有效)。我把它改成这样:

Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                            Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                            Where sd.dorm_building = Session("sdorm").ToString _
                            Select sd.dorm_room)

现在可以了。

My old code looked like this:

Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                            Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                            And sd.dorm_building = Session("sdorm").ToString _
                            Select sd.dorm_room)

And wasn't working (but did work when using MultiViews). I changed it to this:

Dim selectedDorm = (From sd In pcDorms.PBU_WEB_DORMs _
                            Where IIf(Session("sgender").ToString = "M", sd.description = "Male", sd.description = "Female") _
                            Where sd.dorm_building = Session("sdorm").ToString _
                            Select sd.dorm_room)

And now it works.

仅此而已 2024-09-02 19:33:50

不看代码就无法判断;有一个 LINQ 查询从数据库中提取一些信息,现在导致错误。但在没有看到代码的情况下无法告诉你任何事情。

Can't tell without seeing the code; there is a LINQ query that pulls some info from the DB, which is now causing an error. But can't tell you anything without seeing code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文