Solved

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

Posted on 2004-09-07
7
3,084 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 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: 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!

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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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