Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-07
7
Medium Priority
?
3,088 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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