SQL SERVER 2008中用C#定义压缩与解压缩函数
生活随笔
收集整理的這篇文章主要介紹了
SQL SERVER 2008中用C#定义压缩与解压缩函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下面用C#2010定義一個函數,供SQL SERVER 2008使用:
下面是壓縮函數
1 using System.Data.SqlClient; 2 using System.Data.SqlTypes; 3 using Microsoft.SqlServer.Server; 4 using System.Collections; 5 6 public partial class UserDefinedFunctions 7 { 8 [Microsoft.SqlServer.Server.SqlFunction( 9 DataAccess=DataAccessKind.Read, 10 FillRowMethodName="GetNextDepartment", 11 TableDefinition="Name nvarchar(50),GroupName nvarchar(50)")] 12 public static IEnumerable GetDepartments() 13 { 14 // 在此處放置代碼 15 using (SqlConnection conn = new SqlConnection("context connection=true")) 16 { 17 string sql = "Select Name,GroupName From HumanResources.Department"; 18 conn.Open(); 19 SqlCommand comm = new SqlCommand(sql, conn); 20 SqlDataAdapter adaptor = new SqlDataAdapter(comm); 21 DataSet dSet = new DataSet(); 22 adaptor.Fill(dSet); 23 return (dSet.Tables[0].Rows); 24 } 25 } 26 27 public static void GetNextDepartment(object row, 28 out string name, 29 out string groupName) 30 { 31 DataRow theRow = (DataRow)row; 32 name=(string)theRow["Name"]; 33 groupName=(string)theRow["GroupName"]; 34 } 35 };
解壓函數:
?
?
總結
以上是生活随笔為你收集整理的SQL SERVER 2008中用C#定义压缩与解压缩函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转 carrer 之感
- 下一篇: Linux启动报错UNEXPECTED