The AddNew() method uses the parameters "FieldList" and "Values". These
parameters are optional in VB but mandatory in C#.
If I pass null for both I get the following error:
System.Runtime.InteropServices.COMException (0x800A0CC1):
Item cannot be found in the collection corresponding to the requested name
or ordinal.
How can I get around this problem? Any help appreciated.
-Markus Frischholz
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Markus Frischholz" <MarkusFr...@discussions.microsoft.com> wrote in
message news:047CA015-2B28-4129...@microsoft.com...
I was able to work around - but I still wonder how I can deal with optional
parameters in C#. I will try a different newsgroup.
Thanks for your help
-Markus
I don't know C# whatsoever, but I think the Microsoft advice that is
applicable to ADO for VC++ should also do for C#, you just need to
"translate" it from C++ to C#.
In particular the section titled "Missing and Default parameters"
Now in the header file generated by #import I see
HRESULT AddNew (
const _variant_t & FieldList = vtMissing,
const _variant_t & Values = vtMissing );
vtMissing is a global variant generated by #import (and is mentioned in this
document)
You can create equivalents of vtMissing in C# making sure it is has a value
of DISP_E_PARAMNOTFOUND and a type of VT_ERROR and pass that to AddNew as
the first 2 parameters.
Because of the header file generated by #import for VC++, and because
default parameters are supported, I find myself just doing
pRst->AddNew(); // default parameters in C++ are supplying 2
vtMissing's for 2 parameters.
Now I don't really know what support Microsoft has in place for C# and
classic (old-style) ADO. It may well be not much as Microsoft probably
designed C# to work with ADO.NET
I would read the above document carefully.
I am reasonably certain that what you do for C++, you basically adapt for
C#.
You might want to search around from links under
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscusingadowithmicrosoftvisualc.asp?frame=true
Hope this helps
Stephen Howe
Actually I found a solution which is close to your example in C++:
object nil = Type.Missing;
rs.AddNew(nil, nil);
This also works with the Update() method which also takes two optional
parameters.
Thanks again,
-Markus Frischholz