Sharepoint 2007:价值未落在预期范围内

发布于 2024-11-19 10:39:13 字数 2304 浏览 1 评论 0原文

我们有一个列表,在尝试向其中添加新记录时会出现上述错误。下面是该类的完整内容:

Partial Class NextExclusionNo
Inherits System.Web.UI.Page


Private listName As String = "Exclusions List"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim curYear As String = Now.Year.ToString
    curYear = Mid(curYear, 3)

    Dim curMonth As String = Now.Month.ToString
    If curMonth.Length < 2 Then
        curMonth = "0" & curMonth
    End If

    Dim curDay As String = Now.Day.ToString
    If curDay.Length < 2 Then
        curDay = "0" & curDay
    End If

    Dim curObsPrefix As String = "E" & curYear & "-" & curMonth & "-"

    Try
        Using site As New spSite("http://localhost/exclusions")

            Using web As spWeb = site.openweb()

                Dim list As SPList = web.Lists(listName)

                Dim query As New spQuery
                query.query = "<Where><BeginsWith><FieldRef Name='Exclusion_x0020__x0023_' />" & _
                "<Value Type='Text'>" & curObsPrefix & "</Value>" & _
                "</BeginsWith></Where><OrderBy><FieldRef Name='Exclusion_x0020__x0023_' Ascending='False' /></OrderBy>"


                Dim listItems As spListItemCollection = list.getItems(query)

                Dim newReportNo As Integer = 1

                If listItems IsNot Nothing AndAlso listItems.count > 0 Then
                    Dim lastReportNo = listItems.item(0).item("Exclusion_x0020__x0023_")
                    Dim licBits() As String = lastReportNo.split("-")
                    Dim lastNo As Integer = CInt(licBits(2))
                    newReportNo = lastNo + 1
                End If

                Response.Write(getFullReportNo(newReportNo, curObsPrefix))

            End Using

        End Using

    Catch ex As Exception
        Response.Write("Error:" & ex.Message)
    End Try

End Sub

Private Function getFullReportNo(ByRef licNo As Integer, ByRef prefix As String) As String

    Dim lic As String = licNo.ToString
    While lic.Length < 3
        lic = "0" & lic
    End While

    Return prefix & lic

End Function



End Class

上面的内容嵌套在 Try/Catch 块中。谁能帮我诊断并修复上述代码块?非常感谢您的帮助。

We have a list that gives the above error when attempting to add a new record to it. Here's the class in it's entirety:

Partial Class NextExclusionNo
Inherits System.Web.UI.Page


Private listName As String = "Exclusions List"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim curYear As String = Now.Year.ToString
    curYear = Mid(curYear, 3)

    Dim curMonth As String = Now.Month.ToString
    If curMonth.Length < 2 Then
        curMonth = "0" & curMonth
    End If

    Dim curDay As String = Now.Day.ToString
    If curDay.Length < 2 Then
        curDay = "0" & curDay
    End If

    Dim curObsPrefix As String = "E" & curYear & "-" & curMonth & "-"

    Try
        Using site As New spSite("http://localhost/exclusions")

            Using web As spWeb = site.openweb()

                Dim list As SPList = web.Lists(listName)

                Dim query As New spQuery
                query.query = "<Where><BeginsWith><FieldRef Name='Exclusion_x0020__x0023_' />" & _
                "<Value Type='Text'>" & curObsPrefix & "</Value>" & _
                "</BeginsWith></Where><OrderBy><FieldRef Name='Exclusion_x0020__x0023_' Ascending='False' /></OrderBy>"


                Dim listItems As spListItemCollection = list.getItems(query)

                Dim newReportNo As Integer = 1

                If listItems IsNot Nothing AndAlso listItems.count > 0 Then
                    Dim lastReportNo = listItems.item(0).item("Exclusion_x0020__x0023_")
                    Dim licBits() As String = lastReportNo.split("-")
                    Dim lastNo As Integer = CInt(licBits(2))
                    newReportNo = lastNo + 1
                End If

                Response.Write(getFullReportNo(newReportNo, curObsPrefix))

            End Using

        End Using

    Catch ex As Exception
        Response.Write("Error:" & ex.Message)
    End Try

End Sub

Private Function getFullReportNo(ByRef licNo As Integer, ByRef prefix As String) As String

    Dim lic As String = licNo.ToString
    While lic.Length < 3
        lic = "0" & lic
    End While

    Return prefix & lic

End Function



End Class

The above is nested within a Try/Catch block. Can anyone help me diagnose and remedy the above code block? Your help is much appreciated.

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

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

发布评论

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

评论(1

清欢 2024-11-26 10:39:13

根据我的分析,只有您指定的列名称可能会出现此错误。验证您的专栏名称并与我分享您的发现。

As per my analysis only column name which you have specified may give this error. Validate your column name and share me your findings.

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