Cannot compile the following code

G

Guest

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(FillRowMethodName = "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;
}
};
 
C

Carl Daniel [VC++ MVP]

nick said:
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(FillRowMethodName =
"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
 
G

Guest

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::SqlFunctionAttribute::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::FillRowMethodName = "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 said:
nick said:
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(FillRowMethodName =
"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
 
M

Marcus Heege

nick said:
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::SqlFunctionAttribute::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::FillRowMethodName = "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;
}
};


try this

[SqlFunction(FillRowMethodName = "FillRow")]

instead of this

[SqlFunction(SqlFunctionAttribute::FillRowMethodName = "FillRow")]

Marcus
 

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