[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Operator '=' is not defined for type 'DBNull' and string "".

Posted on 2007-04-02
8
Medium Priority
?
2,901 Views
Last Modified: 2008-10-22
Hi Experts,

I am using the following code: -

If Not rs.Fields("Primary").Value = “” Then MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)

The data colum “Primary” sometimes contains no data. When I run the code it comes up: -

Operator '=' is not defined for type 'DBNull' and string "".

How do I resolve this please.

Many Thanks
Lee
0
Comment
Question by:ljhodgett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18838528
Try
If Not IsNull(rs.Fields("Primary").Value) Then...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18838532
If rs.Fields("Primary").Value != DBNull.Value  Then MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18838833
You may also want to check for the actual empty string....

If not (rs.Fields("Primary") Is System.DBNull.Value OrElse rs.Fields("Primary") = String.Empty) Then
  MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)
End if
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Accepted Solution

by:
r1937 earned 1000 total points
ID: 18838889
Try this instead:

If Not rs.Fields("Primary").Value Is DBNull.Value Then MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18838979
If Not isDBNull(rs.Fields("Primary").Value) then
      If Not rs.Fields("Primary").Value = “” Then
            MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)
      end if
end if
0
 

Author Comment

by:ljhodgett
ID: 18839002
Hi,

Thank you for your comments. SirBounty's code does not seem to like "IsNull" I know this is a function of vb6 but it seems as if it has been removed from vb.net unless its called something else.

When I try AngelIII version it comes up: -

Error      97      Identifier expected.      C:\Documents and Settings\eljay\Desktop\vb.net\Stock Control Professional\A.1.1\frmViewSuppliers.vb      139      33      Stock_Control

And underlines the first = of the code.

Best Regards
Lee
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18839038
Import Microsoft.VisualBasic to get the old VB6 functions back...

The != operator is a C# thing... it should be "Not rs.Fields("Primary").Value = DBNull.Value  "

Or you could try mine :)
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18839356
I'm curious... what could the rest of us have done better to be awarded some of the points for this question?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question