Default NULL parameter

M

martin

Hi,

I am using vb.net and I would like to define one of my function parameters
to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody
pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer


Also, how would I explicitly pass a null argument to the function.

many thnaks in advance.

martin.
 
S

Steve C. Orr [MVP, MCSD]

Try this:
Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, Optional ByVal objTran As SqlTransaction = Nothing)
As Integer
 
H

Hans Kesting

martin said:
Hi,

I am using vb.net and I would like to define one of my function parameters
to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody
pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer

I have no experience with vb.net, but I guess you need "DBNull.Value" here.
(DBNull is the class, DBNull.Value is an ("the") instance)
Also, how would I explicitly pass a null argument to the function.

Just write "null" as the argument (by the way: "null" is NOT equal to "DBNull.Value")

Integer res = EnterPractice("thePracticeName", "theUserName", null)

(or should the C# "null" be translated in vb as "Nothing" ??)
 
M

Martin

Thanks guys

cheers

martin


Hans Kesting said:
I have no experience with vb.net, but I guess you need "DBNull.Value" here.
(DBNull is the class, DBNull.Value is an ("the") instance)

Just write "null" as the argument (by the way: "null" is NOT equal to "DBNull.Value")

Integer res = EnterPractice("thePracticeName", "theUserName", null)

(or should the C# "null" be translated in vb as "Nothing" ??)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top