problem with checking null or empty value in detailsview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bob

    problem with checking null or empty value in detailsview

    Hi,

    i want to check whether the textbox of the detailsview is not left empty, in
    insert mode.
    I did this:

    Protected Sub DetailsView1_It emInserting(ByV al sender As Object, ByVal e As
    System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs) Handles
    DetailsView1.It emInserting
    Dim h As String
    h = e.Values("myfie ld")
    'If h = "" Then
    If h Is Nothing Then
    e.Cancel = True
    Label1.Text = "may not be empty."
    End If
    End Sub

    I tried two ways (with ="" and with is nothing), but in both cases, i always
    get the label text and the event is always cancelled, even when i full some
    value.

    So, what's wrong with this code?

    Thanks
    Bob


  • Armin Zingler

    #2
    Re: problem with checking null or empty value in detailsview

    "bob" <bob@gh.vbschri eb
    Hi,
    >
    i want to check whether the textbox of the detailsview is not left
    empty, in insert mode.
    I did this:
    >
    Protected Sub DetailsView1_It emInserting(ByV al sender As Object,
    ByVal e As System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs)
    Handles
    DetailsView1.It emInserting
    Dim h As String
    h = e.Values("myfie ld")
    'If h = "" Then
    If h Is Nothing Then
    e.Cancel = True
    Label1.Text = "may not be empty."
    End If
    End Sub
    >
    I tried two ways (with ="" and with is nothing), but in both cases,
    i always get the label text and the event is always cancelled, even
    when i full some value.
    >
    So, what's wrong with this code?
    First, you should enable Option Strict. The assignment

    h = e.Values("myfie ld")

    is not valid.

    Then, you can examine the return value of e.Values. Maybe it is
    DBNull.Value. If it is, you can do the comparison:

    Dim Value as object
    value = e.Values("myfie ld")

    if value is dbnull.value then
    '...
    end if

    If it's any other value, you will be able to see it in variable
    'value', too.


    Armin

    Comment

    • bob

      #3
      Re: problem with checking null or empty value in detailsview

      Thanks for replying ...
      I tried this:

      Protected Sub DetailsView1_It emInserting(ByV al sender As Object, ByVal e As
      System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs) Handles
      DetailsView1.It emInserting
      Dim h As Object
      h = e.Values("myfie ld")
      If h Is DBNull.Value Then
      e.Cancel = True
      Label1.Text = "may not be empty."
      End If
      End Sub

      But now, the event is never cancelled and every value is accepted. In the
      db, i see NULL when rhe input in the textbox was empty.
      I conclude that 'h' is not DBNULL , but how to cancel the event when the
      input is empty?

      Thanks



      "Armin Zingler" <az.nospam@free net.deschreef in bericht
      news:%23vgcgkur IHA.3456@TK2MSF TNGP05.phx.gbl. ..
      "bob" <bob@gh.vbschri eb
      >Hi,
      >>
      >i want to check whether the textbox of the detailsview is not left
      >empty, in insert mode.
      >I did this:
      >>
      >Protected Sub DetailsView1_It emInserting(ByV al sender As Object,
      >ByVal e As System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs)
      >Handles
      >DetailsView1.I temInserting
      > Dim h As String
      > h = e.Values("myfie ld")
      > 'If h = "" Then
      > If h Is Nothing Then
      > e.Cancel = True
      > Label1.Text = "may not be empty."
      > End If
      > End Sub
      >>
      >I tried two ways (with ="" and with is nothing), but in both cases,
      >i always get the label text and the event is always cancelled, even
      >when i full some value.
      >>
      >So, what's wrong with this code?
      >
      First, you should enable Option Strict. The assignment
      >
      h = e.Values("myfie ld")
      >
      is not valid.
      >
      Then, you can examine the return value of e.Values. Maybe it is
      DBNull.Value. If it is, you can do the comparison:
      >
      Dim Value as object
      value = e.Values("myfie ld")
      >
      if value is dbnull.value then
      '...
      end if
      >
      If it's any other value, you will be able to see it in variable 'value',
      too.
      >
      >
      Armin

      Comment

      • Armin Zingler

        #4
        Re: problem with checking null or empty value in detailsview

        "bob" <bob@gh.vbschri eb
        Thanks for replying ...
        I tried this:
        >
        Protected Sub DetailsView1_It emInserting(ByV al sender As Object,
        ByVal e As System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs)
        Handles
        DetailsView1.It emInserting
        Dim h As Object
        h = e.Values("myfie ld")
        If h Is DBNull.Value Then
        e.Cancel = True
        Label1.Text = "may not be empty."
        End If
        End Sub
        >
        But now, the event is never cancelled and every value is accepted.
        In the db, i see NULL when rhe input in the textbox was empty.
        I conclude that 'h' is not DBNULL , but how to cancel the event when
        the input is empty?
        Use the built-in debugging features. Have you tried logging to debug
        output? For example

        Debug.Print(h.G etType.ToString )


        Armin

        Comment

        Working...