Integer/System.DBNull Values for SQL Delete

TOPIdev

New member
Joined
Sep 8, 2005
Messages
2
Programming Experience
1-3
I'm at a road block with this one.
I need to delete a row from a SQL 2k5 Express database.
All of my parameters are correct but the problem occurs when there might be a Null value or an Integer that needs to be deleted.
I have two public functions that sort which is which...

Public Function nTest(ByVal test as integer) as Integer
Return test
End Function

Public Function nTest(ByVal test as System.DBNull) as System.DBNull
Return Nothing
End Function

So that picks what type of value and works beautifuly for Null values but when I have an Integer, VS.Net says that I have an Invalid Cast Exception in my Delete Statement.

Me.tblTestTableAdapter.Delete(nTest(myVar))

Any ideas.
 
Just use an If statement to determine what the type is:
VB.NET:
If TypeOf myVar Is Integer Then
	'Do something with an Integer here.
Else If TypeOf myVar Is DBNull Then
	'Do something with DBNull.Value here.
End If
 
Deciding what variable is Null is not a problem. The problem is that my Delete statement has 20 variables and some my be Null some of the time and some may not be.
 
Back
Top