Reputation: 7931
I am in the process of converting a VB application to C#. I came across this select statement and am confused why it is even necessary. Isn't the 'case else' just like the default in a C# switch statement?
Select Case dbp.DbType
Case Else
dbcmd.CommandText &= " [" & dbp.ParameterName & "]='" & dbp.Value.ToString().Replace("'", "''") & "'"
End Select
Upvotes: 0
Views: 251
Reputation: 159844
You're correct, it's completely unnecessary. In the absence of all other Case
clauses, this code translates to:
dbcmd.CommandText &= " [" & dbp.ParameterName & "]='" & dbp.Value.ToString().Replace("'", "''") & "'"
Upvotes: 2
Reputation: 32700
Correct; the CASE ELSE
statement in VBA is like the default
statement for a C# switch.
CASE ELSE
and default
will both execute if no other conditions are met; I assume there is more to your VBA code, since a stand-alone CASE ELSE
doesn't make much sense.
Upvotes: 1
Reputation: 17485
The Select Case
code you posted is redundant . As long ass there are no other Case ConditionHere
, the line dbcmd...
will always be executed, i.e. the case statement can be removed.
Upvotes: 1