Hi,

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

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
Dim h As String
h = e.Values("myfield")
'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

Re: problem with checking null or empty value in detailsview by Armin

Armin
Mon May 05 14:49:20 CDT 2008

"bob" <bob@gh.vb> schrieb
> Hi,
>
> i want to check whether the textbox of the detailsview is not left
> empty, in insert mode.
> I did this:
>
> Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
> ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs)
> Handles
> DetailsView1.ItemInserting
> Dim h As String
> h = e.Values("myfield")
> '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("myfield")

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("myfield")

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


Re: problem with checking null or empty value in detailsview by bob

bob
Mon May 05 16:09:56 CDT 2008

Thanks for replying ...
I tried this:

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
Dim h As Object
h = e.Values("myfield")
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@freenet.de> schreef in bericht
news:%23vgcgkurIHA.3456@TK2MSFTNGP05.phx.gbl...
> "bob" <bob@gh.vb> schrieb
>> Hi,
>>
>> i want to check whether the textbox of the detailsview is not left
>> empty, in insert mode.
>> I did this:
>>
>> Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
>> ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs)
>> Handles
>> DetailsView1.ItemInserting
>> Dim h As String
>> h = e.Values("myfield")
>> '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("myfield")
>
> 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("myfield")
>
> 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



Re: problem with checking null or empty value in detailsview by Armin

Armin
Mon May 05 16:46:49 CDT 2008

"bob" <bob@gh.vb> schrieb
> Thanks for replying ...
> I tried this:
>
> Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
> ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs)
> Handles
> DetailsView1.ItemInserting
> Dim h As Object
> h = e.Values("myfield")
> 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.GetType.ToString)


Armin