For example:
public static void FillRow(Object obj, out SqlDateTime timeWritten, out
SqlChars message, out SqlChars category, out long instanceId) 6 5040 public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
public:
static void FillRow(
Object ^ obj,
[Out] SqlDateTime % timeWritten,
[Out] SqlChars ^ % message,
[Out] SqlChars ^ % category,
[Out] long % instanceId);
I believe SqlDateTime is a value class, and SqlChars is a ref class. You
only need the caret for ref classes. The % symbol means pass by reference.
Tom
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.
"Tamas Demjen" wrote: public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
public: static void FillRow( Object ^ obj, [Out] SqlDateTime % timeWritten, [Out] SqlChars ^ % message, [Out] SqlChars ^ % category, [Out] long % instanceId);
I believe SqlDateTime is a value class, and SqlChars is a ref class. You only need the caret for ref classes. The % symbol means pass by reference.
Tom
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;
}
};
Never mind, Sorry I used wrong testing SQL statement.
Thanks very much.
"nick" wrote: 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.
"Tamas Demjen" wrote:
public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
public: static void FillRow( Object ^ obj, [Out] SqlDateTime % timeWritten, [Out] SqlChars ^ % message, [Out] SqlChars ^ % category, [Out] long % instanceId);
I believe SqlDateTime is a value class, and SqlChars is a ref class. You only need the caret for ref classes. The % symbol means pass by reference.
Tom
nick wrote: 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'.
--
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
"Tamas Demjen" wrote: public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
public: static void FillRow( Object ^ obj, [Out] SqlDateTime % timeWritten, [Out] SqlChars ^ % message, [Out] SqlChars ^ % category, [Out] long % instanceId);
I believe SqlDateTime is a value class, and SqlChars is a ref class. You only need the caret for ref classes. The % symbol means pass by reference.
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ian Lazarus |
last post by:
// why is the error message being generated?
// Microsoft Visual C/C++ 5.0
class Bar
{
public:
void Log(const char* p){ }
};
class Foo : public Bar
|
by: Sydex |
last post by:
When I compile code I get error
C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
in this part :
double Integration::quad2d(double...
|
by: Matt |
last post by:
I would like to convert a couple informix stored procedures to SQL
Server stored procedures. I have no idea how to accomplish this. Here
is an example of one of the procedures I need to convert.
...
|
by: Gary |
last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to
int...
Earlier in my code I was setting up my dataset...
I add an int field like so...
...
|
by: Chris Crowe [MVP 1997 -> 2006] |
last post by:
I am having major problems using GetStoredProcCommand and using Parameters
in the same function call in the latest builds of the Enterprise Library
Data.
The error I get is :
Failed to...
|
by: scottrm |
last post by:
I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using...
|
by: LaMoRt |
last post by:
Hi
I want to ask how to convert from long to short since i have some
parameter problem with it?
The problem is like below :
short *speech; // Holds length of any given sample
*...
|
by: GRoll35 |
last post by:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.
All that is suppose to happen is the user enters data and it uses
parent/child class to display...
|
by: Joseph Lu |
last post by:
Hi, I have a multithread problem like the following lines, when I compile
this code I caught a "error C2665", the error description is : none of the
number1 overloads can convert parameter number2...
|
by: xiao |
last post by:
Can I fullfill this task? Using fred and fwrite?
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |