[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

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

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
ljhodgett
Asked:
ljhodgett
1 Solution
 
sirbountyCommented:
Try
If Not IsNull(rs.Fields("Primary").Value) Then...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If rs.Fields("Primary").Value != DBNull.Value  Then MSFlexGrid1.set_TextMatrix(MSFlexGrid1.Rows - 1, 4, rs.Fields("Primary").Value)
0
 
Jeff CertainCommented:
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.

 
r1937Commented:
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
 
YZlatCommented:
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
 
ljhodgettAuthor Commented:
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
 
Jeff CertainCommented:
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
 
Jeff CertainCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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