Click here to Skip to main content
15,895,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error :- Nullable object must have a value.
-----------------------------------------------
Full Error:- at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Nullable`1.get_Value() at System.Nullable`1.op_Explicit(Nullable`1 value) at Sharenote.UI.snCenter.GetNotes()

------------------GetNote()-----------------------------

VB
Private Sub GetNotes()
        Try
            Dim staffID As Integer = CInt(ViewState("staffID"))
            Dim locID As Integer = CInt(ViewState("locID"))
            Dim startDate As Date = CDate(pickStartDate.SelectedDate).ToShortDateString
            Dim endDate As Date = CDate(pickEndDate.SelectedDate).ToShortDateString & " 22:59:59"
            Dim clientIDs As String = "0"
            Dim staffIDs As String = "0"
            Dim serviceIDs As String = "0"
            Dim billingStatusIDs As String = "0"
            Dim noteStatusIDs As String = "0"
            Dim fundingSourceIDs As String = "0"
            Dim caseLoadIDs As String = "0"
            Dim locIDs As String = "0"
            Dim snUser As ShareNoteUser = CType(ViewState("ShareNoteUser"), ShareNoteUser)

            '-- set parameter for users caseload
            If Not snUser.Clients = "0" Then
                caseLoadIDs = snUser.Clients.Replace(",", " ")
            End If
            '-- set parameter for users assigned location(s)
            If Not snUser.Locations = "0" Then
                locIDs = snUser.Locations.Replace(",", " ")
            End If
            Dim ss As New NoteSearchSettings

            If cbShowMulti.Checked = True Then '-- they want search based off of multiple selections
                ss.SelectMulti = True
                For Each li As ListItem In lbxClients.Items
                    If li.Selected = True Then
                        clientIDs = clientIDs & " " & li.Value
                    End If
                Next
                ss.ClientID = 0
                For Each li As ListItem In lbxStaff.Items
                    If li.Selected = True Then
                        staffIDs = staffIDs & " " & li.Value
                    End If
                Next
                ss.StaffID = 0
                For Each li As ListItem In lbxServices.Items
                    If li.Selected = True Then
                        serviceIDs = serviceIDs & " " & li.Value
                    End If
                Next
                ss.ServiceID = 0
                For Each li As ListItem In lbxBillingStatuses.Items
                    If li.Selected = True Then
                        billingStatusIDs = billingStatusIDs & " " & li.Value
                    End If
                Next
                ss.BillingStatusID = 0
                For Each li As ListItem In lbxNoteStatuses.Items
                    If li.Selected = True Then
                        noteStatusIDs = noteStatusIDs & " " & li.Value
                    End If
                Next
                ss.NoteStatusID = 0
                For Each li As ListItem In lbxFundingSources.Items
                    If li.Selected = True Then
                        fundingSourceIDs = fundingSourceIDs & " " & li.Value
                    End If
                Next
                ss.FundSourceID = 0
            Else '-- normal selection method
                ss.SelectMulti = False
                ss.BillingStatusID = ddlBillingStatuses.SelectedValue
                ss.NoteStatusID = ddlNoteStatuses.SelectedValue
                ss.FundSourceID = ddlFundSources.SelectedValue
                If Not ddlServices.SelectedIndex = 0 And Not ddlServices.SelectedIndex = -1 Then
                    ss.ServiceID = ddlServices.SelectedValue
                Else
                    ss.ServiceID = 0
                    ddlServices.SelectedIndex = 0

                End If

                If Not ddlStaffFilter.SelectedIndex = 0 And Not ddlStaffFilter.SelectedIndex = 1 Then
                    ss.StaffID = ddlStaffFilter.SelectedValue
                Else
                    ss.StaffID = 0
                End If
                If Not ddlFilterClients.SelectedIndex = 0 And Not ddlFilterClients.SelectedIndex = 1 Then
                    ss.ClientID = ddlFilterClients.SelectedValue
                Else
                    ss.ClientID = 0
                End If
            End If

            '-- declare new search settings to save
            ss.LocID = locID
            ss.StartDate = startDate
            ss.EndDate = endDate
            ss.ItemsPerPage = ddlItemsPerPage.SelectedValue
            ss.Locked = ddlFilterLocked.SelectedValue
            ss.isGlobal = cbGlobal.Checked
            ss.Trashed = cbTrashed.Checked
            ss.Printed = ddlFilterPrinted.SelectedValue
            ss.LocationIDs = locIDs
            ss.CaseLoadIDs = caseLoadIDs
            ss.isQAQI = snUser.isQAQI
            '-- multi item search selections -- 
            '-- these will be "0" unless something was chosen and the select multi box was checked
            ss.ClientIDs = clientIDs
            ss.StaffIDs = staffIDs
            ss.ServiceIDs = serviceIDs
            ss.FundingSourceIDs = fundingSourceIDs
            ss.BillingStatusIDs = billingStatusIDs
            ss.NoteStatusIDs = noteStatusIDs


            '-- save to session
            Session("NoteSearchSettings") = ss
            '-- Get notes only once
            Try
                pieNotes = DAL.GetPIENotesAndActivity(ss.StaffID, _
                                                      ss.StaffIDs, _
                                                        ss.ClientID, _
                                                        ss.ClientIDs, _
                                                        ss.StartDate, _
                                                        ss.EndDate, _
                                                        CInt(ViewState("locID")), _
                                                        staffID, _
                                                        ss.Trashed, _
                                                        ss.ServiceID, _
                                                        ss.ServiceIDs, _
                                                        ss.NoteStatusID, _
                                                        ss.NoteStatusIDs, _
                                                        ss.BillingStatusID, _
                                                        ss.BillingStatusIDs, _
                                                        ss.FundSourceID, _
                                                        ss.FundingSourceIDs, _
                                                        ss.Locked, _
                                                        ss.Printed, _
                                                        ss.isGlobal, _
                                                        ss.isQAQI, _
                                                        ss.CaseLoadIDs, _
                                                        ss.LocationIDs, _
                                                        CInt(ViewState("providerID")))

                '-- add to the user cache
                If pieNotes.Rows.Count > 250 Then '-- cache the data
                    Cache.Insert(staffID.ToString, pieNotes, Nothing, Now.AddMinutes(5), TimeSpan.Zero)
                Else '-- remove it from the cash if there is something there, dont need to keep it in that memory
                    If Not Cache.Get(ViewState("staffID")) Is Nothing Then
                        Cache.Remove(ViewState("staffID"))
                    End If
                End If


            Catch ex As SqlException
                lblMarquee.Text = ex.ToString
            End Try
        Catch ex As System.Exception
            Response.Redirect(DAL.ErrorReport(Request.Url.AbsoluteUri.ToString, ex.Message.ToString(), DateTime.Now().ToString, ViewState("staffID"), ex.StackTrace.ToString(),
                                              Request.Browser.Browser & " " & Request.Browser.Version, Request.Browser.Platform, Request.ServerVariables("REMOTE_ADDR")), False)
        End Try
    End Sub
Posted
Updated 17-Jun-13 1:33am
v2
Comments
_Amy 17-Jun-13 7:37am    
Which line?

1 solution

You need to make sure the HasValue property is true of Nullable type before accessing its value or casting it to a value type, otherwise you will receive the error mentioned above. Please check below link

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/37d12f4a-0c30-4f72-a446-98e231916824[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900