sqlclr创建表值函数案例

----------------------------------------------:定义表值类型:(1.一定返回的是IEnumerable2.一定带参数3.一定有FillRowMethodName和TableDefinition参数)
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction(DataAccess=DataAccessKind.Read, TableDefinition="Name nvarchar(100),ClassName nvarchar(100)",FillRowMethodName="FillTable",IsDeterministic=true)]
public static IEnumerable TableTest(SqlString str)
{

ArrayList list =new ArrayList{

new Student{ Name="郭泽峰",ClassName="沈阳理工大学103361"},
new Student{Name="郭泽峰1",ClassName="沈阳理工大学103361"},
new Student{Name="郭泽峰2",ClassName="沈阳理工大学103361"},
};
return list;
}
public static void FillTable(object obj, out SqlString name, out SqlString className)
{
Student s = obj as Student;
name = "";
className = "";
if (s != null)
{
name = s.Name;
className = s.ClassName;
}
}
};

posted @ 2014-03-26 14:50  aiaito  阅读(338)  评论(0编辑  收藏  举报