473,757 Members | 10,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Empty field in Access

Hi

I am a beginner in VB.NET, and have a problem with empty field in Access

I have transfered a worksheet in Excel to Access table. Some of the cels are empty
I use VB.NET program to acces this Access table (product.mdb)

One of the statements is to validate whether the field empty or not
My statement is
If Trim(dr_Product ("bt_m3event ")) = "" Or Trim(dr_Product ("bt_m3event ")) = " " The
........
End I

dr_Product ==> is OleDbDataReade
bt_m3event ==>is the field nam

The bt_m3event is empty
When this statement is processed, I got a message like below

An unhandled exception of type 'System.Invalid CastException' occurred in microsoft.visua lbasic.dl
Additional information: Cast from type 'DBNull' to type 'String' is not valid

I have tried so many times and many ways, but it didn't work
Can anybody tell me how to validate an empty field

Thanks in advance

Joachim

Nov 20 '05 #1
3 3021
"Joachim" <an*******@disc ussions.microso ft.com> schrieb
Hi,

I am a beginner in VB.NET, and have a problem with empty field in
Access.

I have transfered a worksheet in Excel to Access table. Some of the
cels are empty. I use VB.NET program to acces this Access table
(product.mdb).

One of the statements is to validate whether the field empty or
not. My statement is :
If Trim(dr_Product ("bt_m3event ")) = "" Or
Trim(dr_Product ("bt_m3event ")) = " " Then
.........
End If

dr_Product ==> is OleDbDataReader
bt_m3event ==>is the field name

The bt_m3event is empty.
When this statement is processed, I got a message like below :

An unhandled exception of type 'System.Invalid CastException' occurred
in microsoft.visua lbasic.dll Additional information: Cast from type
'DBNull' to type 'String' is not valid.

I have tried so many times and many ways, but it didn't work.
Can anybody tell me how to validate an empty field ?

First, you should enable Option Strict. Your code can not be compiled here
because the type of the DataReader's Item property is Object. You can not
compare every object to a string and you can't pass it to the Trim function.

As the exception message says, the field contains a Null value. The only
instance of Null in the Framework is DBNull.Value:

If dr_Product("bt_ m3event") Is DBNull.Value Then
msgbox "Null found"
else
dim FieldContent as string
FieldContent = dr_Product("bt_ m3event").ToStr ing
end if

For all other date types, you must use type casting:

If dr_Product("Any IntegerField") Is DBNull.Value Then
msgbox "Null found"
else
dim FieldContent as Integer
FieldContent = Directcast(dr_P roduct("bt_m3ev ent"), Integer)
end if
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "=?Utf-8?B?Sm9hY2hpbQ= =?=" <an*******@disc ussions.microso ft.com> scripsit:
I have transfered a worksheet in Excel to Access table. Some of the cels are empty.
I use VB.NET program to acces this Access table (product.mdb).

One of the statements is to validate whether the field empty or not.
My statement is :
If Trim(dr_Product ("bt_m3event ")) = "" Or Trim(dr_Product ("bt_m3event ")) = " " Then


'If dr_Product("bt_ m3event") Is DBNull.Value Then...'. The right part of
the 'Or' IMO doesn't make sense at all because 'Trim' will remove the spaces.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Armin and Herfried
Thanks to you. It works
But I have another problem. I have posted it in the other thread
I think you can help me out.
Nov 20 '05 #4

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

Similar topics

1
5038
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
3
8899
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; ?>
5
7105
by: Adrian Parker | last post by:
Hi. I have a date time picker in my program which uses ADO to read from an Access database. It works perfectly, unless the database is empty (no records) when opened. When you try to open an empty database, the date time picker returns error 545. Any attempts to progmatically add new records after the empty database has been opened returns, or to use the DTP and set a new date for those added records, "Field not updateable, Bound...
5
24637
by: Krechting | last post by:
Hi ALl, I have a code that checks if the documents in a hyperlink field are still where they should be. I use fileexist(). First I want to filter out all the hyperlink fields that are empty. I open a recordset and browse through all the fields to check for the word file. I cannot filter out the empty fields. I have tried: If Len(.Fields("Link") <> 0 then and: If Not IsNull(.Fields("Link")) then
8
10409
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
2
1746
by: ET | last post by:
Hi! I'll need help on what todo with this information in table... There has to be a unique on one column (Item ID, for inventory purpose) but in many cases that ID is not known... thus, many empty records for that column exist in a table. I tried to create unique index (no duplicates), of course, it failed because of many empty records... Now, is there ANY way to keep those empty records, and allow new empty
2
1539
by: AA Arens | last post by:
I have button and added the command that places a date and some stripes in the Notes-field. That works fine. If there is already some text, it places the date at a next line: Private Sub Command80_Click() Me.Notes = Me.Notes & vbCrLf & Format(Date, "dd-mm-yyyy") & " ------ " Notes.SetFocus Notes.SelStart = Len(Notes.Value) End Sub
1
6213
by: G04 | last post by:
Hi All, I have a continuous form with all records. For each field there is a combo in the form header and the form also contains a Toggle button "Apply Filter". When clicked, it changes to "Cancel Filter". Then an SQL string with condition meeting the criteria input in the combo boxes is built. I have noticed that when certain fields are not filled in (no space, nothing), the record is simply not shown. The empty field is not necessarily...
0
1050
by: Mich | last post by:
Hi, i made a gridview connected to a sql server db and i need to test the value of a field of the gridview.. The problem is that field can be empty (e.g. when the content of that field was previously deleted by another query) or NULL. Now, when i try to access a record where that field has content, no problem, but if it's empty or NULL, i get the error: "Object reference not set to an instance of an object"
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9737
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.