473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with checking null or empty value in detailsview

bob
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
Jun 27 '08 #1
5 3623
"bob" <bo*@gh.vbwro te in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl...
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 <== is this supposed to be commented?
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?
Firstly, you appear to have commented the line which I've highlighted, which
means that the corresponding End If must also be commented, otherwise the
code won't compile... I'm assuming you're using Option String...?

However, more fundamentally, a string variable can never really be a null
value, so it will never equate to Nothing in VB.NET...

Also, you appear not to be using any exception handling...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:ee******** *****@TK2MSFTNG P02.phx.gbl...
code won't compile... I'm assuming you're using Option String...?
Apologies - I mean Option Strict...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3
"bob" <bo*@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

Jun 27 '08 #4
bob
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*******@free net.deschreef in bericht
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
"bob" <bo*@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

Jun 27 '08 #5
"bob" <bo*@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

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8878
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
15
12769
by: Robert Mark Bram | last post by:
Hi All! I have the following code in an asp page whose language tag is: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%> // Find request variables. var edition = Request.Form ("edition"); var language = Request.Form ("language"); Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and value &quot;" + edition + "&quot;<br>");
2
1299
by: Jonas Hansson | last post by:
Hi, I have a problem regarding NULL values in a database when I retrieve the data with the MySqlDataAdapter fill a DataSet with the returned value. Whenever the SQL statement returns data that has a column of which the first row has the value NULL, that whole column will be NULL for all retrieved rows. Do I have to set a specific value in the...
4
1252
by: luna | last post by:
could someone explain the meaning behind :- System.IndexOutOfRangeException: firstname1 when the code is :- If objDR("firstname1") Is System.DBNull.Value Then firstname1.Text = "" Else : firstname1.Text = objDR("fname1") End If
1
2931
by: David Lozzi | last post by:
Howdy, I am trying to accomplish the following: dim DateSend as date if txtDateSend.text = "" then DateSend = dbnull.value else DateSend = txtDateSend.text
3
1213
by: Trapulo | last post by:
I've some problem checking items in a checkedlistbox by code: For jj As Int32 = 0 To cbTimeOptions.Items.Count - 1 ' cut: logic to set maycheck variable cbTimeOptions.SetItemChecked(jj, maycheck ) Next
11
3341
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this...
4
4887
by: John Kotuby | last post by:
Hi all, I have a simple user-form which accepts contact and profile information for the user to edit and save. All the textboxes are working fine and displaying the expected data, both when the screen is first displayed and after a save of changed data. The text boxes are being populated during the Page_Load event. However, when I change...
3
1527
gingawarrior
by: gingawarrior | last post by:
Hi All, I've written some code to act as a validator for a set of form fields - it accepts a string of '~' delimited item names and then loops through to evaluate if they are either empty or =='999' (default not selected for a dropdown list). So far so good...however, although the value=='999' bit works, those fields that post a null or empty...
19
8304
by: Alino | last post by:
how do i clonenode for example an div tag where are one text input field and two option tags to make that new cloned input field with an empty value? Thank you.
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.