Solved

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

Posted on 2004-09-07
7
3,077 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 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now