Optional values?

Ö

Özden Irmak

Hi,

In my C# applicaiton, I use ADOX to reach and check the user permissions in
my Access database. To do this, there is a function named "GetPermissions".
This function gets 3 arguments where the 3rd one is optional. But the C#
compiler doesn't accept giving only 2 parameters and whatever I put into the
third one (null, "", etc.) I get an exception.

I want to ask whether anybody knows how to handle those optional parameters
in C#?

Thanks in advance...

Regards,

Özden
 
J

Josema

I think that if this optional parameter is of type string, or object will
allow you put it to null.

Regards.
Josema.
 
M

Michael Voss

Özden Irmak wrote:

[...snip...]
there is a function named "GetPermissions".
This function gets 3 arguments where the 3rd one is optional. But the C#
compiler doesn't accept giving only 2 parameters and whatever I put into the
third one (null, "", etc.) I get an exception.

I want to ask whether anybody knows how to handle those optional parameters
in C#?
[...snip...]

AFAIK, C# does not support optional parameters. You can set each parameter
to null, as long as the parameter type supports it, but you'll need to check
in your method and act appropriate.

Can you tell us what exception you get and how your function looks like ?
 
C

Carlos J. Quintero [.NET MVP]

Try passing System.Type.Missing for missing optional parameters.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
C

Christof Nordiek

Hi Özdem,

not sure, but i think this should work:

object = System.Reflection.Missing.Value;
myAdox.GetPersmission(param1, param2, missing);

Christof
 
Ö

Özden Irmak

Hi,

Thank you all first of all...

System.Reflection.Missing.Value still throws the same exception...



This is the function that I'm trying to use (Taken from ADO help) :




Gets the permissions for a group or user on an object.

Syntax

ReturnValue = GroupOrUser.GetPermissions(Name, ObjectType
[, ObjectTypeId])

Return Value

Returns a Long value specifying a bitmask containing the permissions that
the group or user has on the object.

Parameters

Name A String value specifying the name of the object for which to set
permissions.

ObjectType A Long value specifying the type of the object for which to get
permissions. The following constants are valid values for ObjectType:

Constant Description
adPermObjProviderSpecific Object is of a provider-defined type. An
error will occur if the ObjectType is adPermObjProviderSpecific and an
ObjectTypeId is not supplied.
adPermObjTable Object is a table.
adPermObjColumn Object is a column.
adPermObjDatabase Object is a database.
adPermObjProcedure Object is a procedure.
adPermObjView Object is a view.
adPermObjSchema Object is a schema.
adPermObjDomain Object is a domain.
adPermObjCollation Object is a collation.
adPermObjSchemaRowset Object is a schema rowset.
adPermObjCharacterSet Object is a character set.
adPermObjTranslation Object is a translation.


ObjectTypeId Optional. A Variant value specifying the GUID for a provider
object type not defined by the OLE DB specification. This parameter is
required if ObjectType is set to adPermObjProviderSpecific; otherwise, it is
not used.







The exception detail is this :

System.Runtime.InteropServices.COMException was unhandled


Regards,

Özden
 
S

Saurabh

Any more details as to what makes you think that the exception is being
thrown only because of the optional parameter rather than something else?

--Saurabh

Özden Irmak said:
Hi,

Thank you all first of all...

System.Reflection.Missing.Value still throws the same exception...



This is the function that I'm trying to use (Taken from ADO help) :




Gets the permissions for a group or user on an object.

Syntax

ReturnValue = GroupOrUser.GetPermissions(Name, ObjectType
[, ObjectTypeId])

Return Value

Returns a Long value specifying a bitmask containing the permissions that
the group or user has on the object.

Parameters

Name A String value specifying the name of the object for which to set
permissions.

ObjectType A Long value specifying the type of the object for which to
get permissions. The following constants are valid values for ObjectType:

Constant Description
adPermObjProviderSpecific Object is of a provider-defined type. An
error will occur if the ObjectType is adPermObjProviderSpecific and an
ObjectTypeId is not supplied.
adPermObjTable Object is a table.
adPermObjColumn Object is a column.
adPermObjDatabase Object is a database.
adPermObjProcedure Object is a procedure.
adPermObjView Object is a view.
adPermObjSchema Object is a schema.
adPermObjDomain Object is a domain.
adPermObjCollation Object is a collation.
adPermObjSchemaRowset Object is a schema rowset.
adPermObjCharacterSet Object is a character set.
adPermObjTranslation Object is a translation.


ObjectTypeId Optional. A Variant value specifying the GUID for a
provider object type not defined by the OLE DB specification. This
parameter is required if ObjectType is set to adPermObjProviderSpecific;
otherwise, it is not used.







The exception detail is this :

System.Runtime.InteropServices.COMException was unhandled


Regards,

Özden







Özden Irmak said:
Hi,

In my C# applicaiton, I use ADOX to reach and check the user permissions
in my Access database. To do this, there is a function named
"GetPermissions". This function gets 3 arguments where the 3rd one is
optional. But the C# compiler doesn't accept giving only 2 parameters and
whatever I put into the third one (null, "", etc.) I get an exception.

I want to ask whether anybody knows how to handle those optional
parameters in C#?

Thanks in advance...

Regards,

Özden
 
Ö

Özden Irmak

Hi,

Ok, it is working now, there was another small problem in the code, where we
were trying to get permission of a column object...

Thank you all for taking time and trying to help me...

Regards,

Özden Irmak
 
Top