原文连接:http://www.c- sharpcorner.com/UploadFile/pk_khuman/ManagedUserDefinedFunctionUsingCSharp02212007015548AM/

ManagedU serDefinedFunctionUsingCSharp.aspx


C#写托管的用户自定义 函数
<?xml:namespace prefix = o ns = "urn:schemas-microsoft- com:office:office" />

 

 

简介

随着SQL Server 2005中集成了CLR,我们可以使用现代面向对象语言例如VB.NET,C#来建立数据库对象.

本文将用简单而必须的步骤来说明如何开始使用C#来建立托管的用 户自定义函数.

顼目
 

我们将为托管的触发 器建立一个Visual Studio 2005数据库项目
建立数据库项目

打开Microsoft Visual Studio 2005建立一个SQL Server项目
File->New->Project- >Database 

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />用C#写托管的用户自定义函数(翻译三)

添加一个数据库引用

现在它会需要一个数据库的引用,添加一个。

用C#写托管的用户自定义函数(翻译三)

添加一个用户自定义函数


右击项目并且建立一个用户自定 义函数

用C#写托管的用户自定义函数(翻译三)

The file Function1.cs:

 

将下面的代码复制到文件Function1.cs

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using Microsoft.SqlServer.Server;

 

public partial class UserDefinedFunctions

{

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlInt64 Function1(SqlInt<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />32 a, SqlInt32 b)

    {

        // Put your code here

        // return new SqlString ("Hello");

        return (a + b);

    }
};

部署用户自定义函数

 

建立并部署项目

用C#写托管的用户自定义函数(翻译三)

测试触发器


用下面的SQL语句来确保CLR可以在你的SQL Server中运行

sp_configure 'clr enabled', 1;

GO

RECONFIGURE;
GO


现在执行这个带两个整型参数的 函数

用C#写托管的用户自定义函数(翻译三)

转载于:https://www.cnblogs.com/TtTiCk/archive/2007/04/14/712771.html

相关文章:

  • 2021-08-03
  • 2021-08-19
  • 2021-07-11
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-05
  • 2021-09-01
  • 2021-07-28
  • 2021-12-26
  • 2022-02-08
相关资源
相似解决方案