Cannot Add/Edit/Remove Events - Unhandled Exception RRS feed

  • Question

  • User1479750397 posted

    I get the following errors when I try and do anything with events.  The first time I could add one but now nothing works.  What's going on and did the rest of you experience this as well?  Its hard to believe these templates were released with so many problems!

    Conversion from type 'DBNull' to type 'String' is not valid.

    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.InvalidCastException: Conversion from type 'DBNull' to type 'String' is not valid.

    Source Error:

    Line 43:                     Case Else
    Line 44:                         'We are in edit mode
    Line 45:                         Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)
    Line 46:                         Dim surl As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)
    Line 47:                         If Not surl.Text Is Nothing AndAlso surl.Text <> "" Then

    Source File: d:\hosting\s3rock\Events_Edit.aspx    Line: 45
    Wednesday, March 22, 2006 1:21 PM

All replies

  • User-1476513399 posted

    Well, not exactly sure why you are getting DBNull error at that point in the code (there are several other places where it does occur in the app), however that entire section of the code has a problem.  I should look like what I've posted below.

    What's wrong with the existing code is that ... the 'Case Else' should not be part of the Select Case statement.  Instead, it needs to be the 'Else' condition for the 'If Not action' statement above the Select Case statement. I discovered this troubleshooting a different problem in this section.  It turns out the 'action' Is Nothing when the Edit mode is called!!

    Also .. in the original code ... there is a Case "delete".  This should be Case "remove".  Otherwise, nothing happens when you try to 'Remove' an event in the Events List view (if you are logged as Administors) because a 'remove' is being sent instead of 'delete'. Also, a remove confirmation should be placed here!!!!  Not exactly what I would call 'best practice' w/o a confirmation !!!

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

    If Not IsPostBack Then

    'Initialize the fields

    Dim action As Object = Request.QueryString("Action")

    If Not action Is Nothing Then

    Select Case LCase(CStr(action))

    case "new"

    'We are in new mode


    Dim lp As LocationsPicker = CType(FormView1.FindControl("LocationPicker1"), LocationsPicker)

    lp.LocationID = Nothing

    Dim dp As DurationPicker = CType(FormView1.FindControl("dtpicker"), DurationPicker)

    dp.startDateTime = Now

    dp.endDateTime = Now.AddHours(3)

    Dim slp As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)

    slp.Enabled = False

    Case "remove"



    End Select


    'We are in edit mode

    Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)

    Dim surl As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)

    If Not surl.Text Is Nothing AndAlso surl.Text <> "" Then

    cb.Checked = True

    surl.Enabled = True


    surl.Enabled = False

    End If

    End If

    End If

    End Sub


    Thursday, March 23, 2006 12:10 AM
  • User1479750397 posted
    The problem had to do with Locations having Null fields in the description and direction fields.  Once I fixed them, I could then edit/add events.
    Thursday, March 23, 2006 8:36 AM
  • User-1476513399 posted

    Well, those fields should NOT have to be required.  You need to check for nulls in code.  The user should not be required to enter any thing in those fields.  The same problem exists for the Description field in the Events section.  Try it. 

    And ... there are a least 4 different places on two different pages where the Event Description is displayed ... and you will get the exact same error - for the same reason.  The Description should not be required ... it s/b tested for nulls before displaying.  And actually, in the place where there errors occur ... I don't see why CStr is even needed ... it's already a text field! 

    If you check out this post http://forums.asp.net/1194730/ShowPost.aspx lutz2 has a good fix 'quick fix' that I used.  You can apply it to your situation above.  Also, you should modify that code section per my post above ... because that fixes another problem unrelated to the DBNull error.


    Thursday, March 23, 2006 2:19 PM