?
Solved

Operator is not valid for type 'DBNULL' and string....

Posted on 2004-09-07
7
Medium Priority
?
3,091 Views
Last Modified: 2012-08-13
Hello experts!

I recently altered one of my datagrids I use and added a dropdownlist, a checkbox, and another simple textbox.  I setup my sql table like I always do for checkboxes and what not.  For some reason when you now edit a new row that's been added to the grid I get the following error:


Operator is not valid for type 'DBNull' and string "Service".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Operator is not valid for type 'DBNull' and string "Service".

Source Error:


Line 206:                        If AddingNew = False And Not (Val Is Nothing) Then
Line 207:                              Select Case Val
Line 208:                                    Case "Service"
Line 209:                                          Return 1
Line 210:                                    Case "Parts"
 

Source File: c:\inetpub\wwwroot\BadChecks\datagrid1130test.aspx    Line: 208

How do I get it to recognize the empy/null sql field and move past it?  The code its hanging up on is here:

Function dgDropDown1GetIDX(ByVal Val As Object) As Integer
If AddingNew = False And Not (Val Is Nothing) Then
      Select Case Val
            Case "Service"
            Return 1
            Case "Parts"
            Return 2
            Case "B/S"
            Return 3
            Case "New Sales"
            Return 4
            Case "Used Sales"
            Return 5
            Case Else
            Return 0
      End Select
Else
Return 0
End If
End Function

Any ideas?  I use this function to get the value that is already in the sql table.  

Help!
0
Comment
Question by:jay-are
  • 4
  • 2
7 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12001079
If AddingNew = False And Not (Val Is Nothing) And not isdbnull(val) Then
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 2000 total points
ID: 12001083
or use Select Case (Val & "")
0
 

Author Comment

by:jay-are
ID: 12001577
Thanks for your feedback!

Will be testing...
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 18

Expert Comment

by:DotNetLover_Baan
ID: 12001948
Cool... Greg.. that's a nice trick... >> Select Case (Val & "") << ...   awsome...
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12002318
dbnull & "" = "" always :)
0
 

Author Comment

by:jay-are
ID: 12002719
Select Case (Val & "")

works perfect...so simple too!

Thanks!
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12003027
glad to hear it, let me know if you need anything else.

Cheers,

Greg
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 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