Thanks, yes, i forgot using the namespace. However, the code still cannot be
compiled:
Error 1 error C2597: illegal reference to non-static member
'Microsoft::SqlServer::Server::SqlFunctionAttribut e::FillRowMethodName'
when compiling
#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;
// select dbo.MyUDF()
// go
public ref class AddNewUDF
{
public:
[SqlFunction(SqlFunctionAttribute::FillRowMethodNam e = "FillRow")]
static IEnumerable^ MyUDF()
{
SqlTypes::SqlString Value(L"Hello");
DataTable dt;
dt.Rows->Add("");
return dt.Rows;
}
static void FillRow(Object obj, SqlChars^ message, SqlChars^ category,
long^ instanceId)
{
message = gcnew SqlChars("Test");
category = gcnew SqlChars("Test");
instanceId = 123;
}
};
"Carl Daniel [VC++ MVP]" wrote:
"nick" <ni**@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com... Seems the FillRowMethodName caused the problem?
C# works. but not C++?
using namespace System;
using namespace System::Data;
using namespace System::Data::Sql;
using namespace System::Data::SqlTypes;
using namespace Microsoft::SqlServer::Server;
public ref class AddNewUDF
{
public:
[Microsoft::SqlServer::Server::SqlFunction(FillRowM ethodName =
"FillRow")]
static IEnumerable MyUDF()
{
// Put your code here
SqlTypes::SqlString Value(L"Hello");
return Value;
}
static void FillRow(Object obj, SqlChars^ message, SqlChars^ category,
long^ instanceId)
{
message = gcnew SqlChars("Test");
category = gcnew SqlChars("Test");
instanceId = 123;
}
};
You need to add #using <system.data.dll> so that those namespaces are
visible to the compiler. I think you can add a reference at the project
level instead, but I can't check that right now.
-cd