I'm trying to create a table based function using SMO. The problem is that I get an error saying that I need to set the DataType property on the function before it can be created. However, the documentation clearly says that the DataType property is null for Table based functions. I can't even set this value to null either!
Here's a code snippet that shows what I'm trying to do.
if (returnType.ToLower() != "table")
{
Type clrDataType = Type.GetType(returnType);
returnSqlDataType = GetSqlDataType(clrDataType);
function.FunctionType = Smo.UserDefinedFunctionType.Scalar;
function.DataType = returnSqlDataType;
}
else
{
function.FunctionType = Smo.UserDefinedFunctionType.Table;
function.TableVariableName = xmlNode.Attributes["tableVariableName"].Value;
XmlNode returnTableDescription = GetChildOfParent(xmlNode, "ReturnTableDescription");
XmlNode columnsNode = GetChildOfParent(returnTableDescription, "Columns");
foreach (XmlNode columnNode in columnsNode.ChildNodes)
{
function.Columns.Add(CreateUdfColumn(function, columnNode));
}
}
The xmlNode that is being referenced is an XmlNode that is describing how to create the table. returnType is a variable that is set from one of the xmlNode's attributes.
When I call on function.Create() then I get the error that I posted above. Any help anyone can give is appreciated. One thing I also tried doing was to connect to an already existing Table based function and look at its SMO properties. Sure enough, its DataType property was null.
MSFT: Is this a bug?
Never mind on this post.....it was my mistake. The DataType property not being set wasn't on the function itself, but rather on the columns collection.
Problem solved.
No comments:
Post a Comment