Tintin
Tintin

Reputation: 2983

How do you assign null value to optional parameters in VB.NET 1.1

I tried DbNull.Value but no luck. How do I assign a default value as null to a string parameter that is null in VB.NET? Its litte strange to see that VB does not have anything like plain null as most of the other languages do. Also what is the difference between null and DbNull and Nothing. Thanks Guys.

Upvotes: 4

Views: 16791

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 416059

VB.Net's closest equivalent to null is Nothing.

Note that this isn't a direct analog to C#'s null, but rather a closer match for C#'s default(T). However, it should do what you need here.

Upvotes: 2

Michael Sagalovich
Michael Sagalovich

Reputation: 2549

Nothing is what you use in VB for null, so VB has no null, and DBNull is to be used to pass null to database when, for example, you are constructing a call to stored procedure and one of its input parameters needs to be null.

Upvotes: 5

Geoff Appleford
Geoff Appleford

Reputation: 18832

use nothing instead of null

Upvotes: 2

Related Questions