Solved

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

Posted on 2004-09-07
7
3,078 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

943 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

7 Experts available now in Live!

Get 1:1 Help Now