Thanks, after add % and [Out] (seems it works fine without [Out] too?). The
code finally works.
However, when debugging, I keep get:
Cannot find either column "dbo" or the user-defined function or aggregate
"dbo.MyUDF", or the name is ambiguous.
> > public static void FillRow(Object obj, out SqlDateTime timeWritten, out
> > SqlChars message, out SqlChars category, out long instanceId)
[quoted text clipped - 11 lines]
>
> Tom
nick - 18 Apr 2006 22:37 GMT
Btw, the code:
#include "stdafx.h"
using namespace System;
using namespace System::Data;
using namespace System::Data::Sql;
using namespace System::Data::SqlTypes;
using namespace Microsoft::SqlServer::Server;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;
// select dbo.MyUDF()
// go
public ref class AddNewUDF
{
public:
[SqlFunctionAttribute(
FillRowMethodName = "FillRow",
TableDefinition = "Message nvarchar(20), Category nvarchar(10),
instanceId Int"//
)]
static IEnumerable^ MyUDF()
{
DataTable dt;
dt.Columns->Add("Test");
dt.Rows->Add(1);
return dt.Rows;
}
static void FillRow(Object obj, [Out] SqlChars^ % message, [Out]
SqlChars^ % category, [Out]long % instanceId)
{
message = gcnew SqlChars("Test");
category = gcnew SqlChars("Test");
instanceId = 212;
}
};
nick - 18 Apr 2006 22:50 GMT
Never mind, Sorry I used wrong testing SQL statement.
Thanks very much.
> Thanks, after add % and [Out] (seems it works fine without [Out] too?). The
> code finally works.
[quoted text clipped - 19 lines]
> >
> > Tom
Tamas Demjen - 18 Apr 2006 23:57 GMT
> Thanks, after add % and [Out] (seems it works fine without [Out] too?).
C#: void f(ref int x);
same as
C++: void f(int% x);
C#: void f(out int x);
same as
C++: void f([Out] int% x);
The only difference is the [Out] attribute, which I think is mainly used
to determine the marshalling strategy. The [Out] attribute suggests that
the function doesn't use the argument as an input, it is strictly an
output, so it only needs to be marshalled in one direction. If you omit
[Out], it suggests that the function reads AND writes the given
argument, and therefore it must be marshalled back and forth. The
difference may not be important in a desktop application, but in a Web
service (or any distributed system) you might want to pay attention to
these details, in order to avoid unnecessary network traffic.
Example:
void GetValue([Out] int% x) { x = 10; }
// x is written only
void AddValue(int% x) { x = x + 10; }
// x is read and written
Tom
BTW, 'long' in C# is Int64 in C++/CLI, not 'long'.

Signature
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
> > public static void FillRow(Object obj, out SqlDateTime timeWritten, out
> > SqlChars message, out SqlChars category, out long instanceId)
[quoted text clipped - 11 lines]
>
> Tom