Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

null value

I have a application in visual basic with access as backend
In the form if I take value for any text box and save it in the database
And next time while editing if I try to make it null and save it
Next time I get the error invalid use of null although I have checked for no values required
In the access and default value to “”

0
leenapedenekar
Asked:
leenapedenekar
1 Solution
 
GrahamSkanCommented:
It sounds as if you are succcessfully reading a null value from the database and then trying to do something with it in VB that cannot be done with a Null.
You'll need to test for null before you use it.

If Not MyVariable Is Null Then
...
End If
0
 
ColosseoCommented:
Graham should that not be

If Not IsNull(MyVariable) Then
...
End If
0
 
Ryan ChongCommented:
also can try like below, if you want to retrieve values from your db to textbox:

text1.text = "" & Rs("myfield")

this will make you ease and no need to check whether the value return is null or not.
0
 
GrahamSkanCommented:
Yes, Colloseo, you are right. A senior moment. I'm afraid.
0
 
JR2003Commented:
leenapedenekar

ryancys solution is probably the neatest for any text field.
Anytime you receive some text from the database that could possibly be null, just add & "" on the end of the line.

e.g. Text1.Text = Rs("myfield").Value & ""  

For date and numeric fields that can possibly be null just use the IsNull function

If IsNull(Rs("myfield").Value) Then
...
Else
...
End IF

JR
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now