用C#写托管的存储过程 (翻译一)
2007-03-21 23:56
239 查看
原文连接:
http://www.c-sharpcorner.com/UploadFile/pk_khuman/ManagedStoredProceduresUsingCSharp02182007232059PM/ ManagedStoredProceduresUsingCSharp.aspx
介绍
随着SQL Server 2005中集成了CLR,我们可以用现代面向对象语言例如VB.NET 和C# 来建立数据库对象.事实上,为了抽象出如计算,字符串逻辑分析等与数据库无关的存取代码,我们使用.NET来写SQL Server的对象.最好用托管代码来写存储过程.同样的为了访webservices,为OOP编程提供更好的可复用性和读取外部文件,托管的存储过程也是一个不错的选择.
This article is trying to explain the simple and required steps that are require starting the creation of Manage Stored Procedure using C# and using them.
这篇文章将会用简单而必需的步骤来说明如何使用C#来建立托管的存储过程,还有如何使用.
项目
我们将为托管的存储过程建立一个Visual Studio 2005的数据库项目
建立数据库项目:
打开微软的Visual Studio 2005建立一个SQL Server的项目
File->New->Project->Database
添加一个数据库引用
现在将会需要一个数据库的引用,添加一个
添加存储过程
右击项目添加一个存储过程
SPOne.cs文件
下面为SPOne.cs文件的代码.确保你的数据库里面存在Person表 或者用你数据库中的表替代Person表
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void SPOne()
{
SqlPipe p;
SqlCommand sCmd = new SqlCommand();
sCmd.CommandText = "Select * from Person";
p = SqlContext.Pipe;
p.ExecuteAndSend(sCmd);
}
};
部署存储过程
建立并部署项目
运行存储过程
用下面的SQL语句来验证CLR可以在你的SQ: Server中运行.
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
Now execute the Stored Procedure and you will get an output of select statement.
Make your Life follows Procedures and Stored them safely! If possible, manage them!!!!
http://www.c-sharpcorner.com/UploadFile/pk_khuman/ManagedStoredProceduresUsingCSharp02182007232059PM/ ManagedStoredProceduresUsingCSharp.aspx
介绍
随着SQL Server 2005中集成了CLR,我们可以用现代面向对象语言例如VB.NET 和C# 来建立数据库对象.事实上,为了抽象出如计算,字符串逻辑分析等与数据库无关的存取代码,我们使用.NET来写SQL Server的对象.最好用托管代码来写存储过程.同样的为了访webservices,为OOP编程提供更好的可复用性和读取外部文件,托管的存储过程也是一个不错的选择.
This article is trying to explain the simple and required steps that are require starting the creation of Manage Stored Procedure using C# and using them.
这篇文章将会用简单而必需的步骤来说明如何使用C#来建立托管的存储过程,还有如何使用.
项目
我们将为托管的存储过程建立一个Visual Studio 2005的数据库项目
建立数据库项目:
打开微软的Visual Studio 2005建立一个SQL Server的项目
File->New->Project->Database
添加一个数据库引用
现在将会需要一个数据库的引用,添加一个
添加存储过程
右击项目添加一个存储过程
SPOne.cs文件
下面为SPOne.cs文件的代码.确保你的数据库里面存在Person表 或者用你数据库中的表替代Person表
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void SPOne()
{
SqlPipe p;
SqlCommand sCmd = new SqlCommand();
sCmd.CommandText = "Select * from Person";
p = SqlContext.Pipe;
p.ExecuteAndSend(sCmd);
}
};
部署存储过程
建立并部署项目
运行存储过程
用下面的SQL语句来验证CLR可以在你的SQ: Server中运行.
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
Now execute the Stored Procedure and you will get an output of select statement.
Make your Life follows Procedures and Stored them safely! If possible, manage them!!!!
相关文章推荐
- 用C#写托管的用户自定义函数(翻译三)
- CLR_via_C#.3rd 翻译[1.1将源文件编译为托管模块]
- 用C#写托管触发器(翻译二)
- CLR_via_C#.3rd 翻译[1.2将托管模块组合到集]
- C#怎么调用SQL Server的存储过程
- 怎样迅速成为一个有经验的开发人员(翻译自奥马扎贝尔的blog-C#MVP)
- C#使用存储过程详细
- 使用C#创建SQL Server的存储过程
- C#中用Oracle 执行存储过程返回DataSet
- [翻译]使用C#创建SQL Server的存储过程(Visual Studio 2005 + SQL Server 2005) (转)
- c# 托管堆,堆栈【图文非常详细】
- C#调用存储过程
- C#实现UBB翻译,网站经常用到的哦
- C#二十六 使用Ado.Net调用存储过程
- [翻译]使用C#创建SQL Server的存储过程(Visual Studio 2005 + SQL Server 2005)【转】
- c# asp.net winform 调用存储过程的通用类
- CLR_via_C#.3rd 翻译[25.5 NUMA架构]
- c#通过存储过程 out参数输出正常数据和count
- C#托管代码与C++非托管代码互相调用二(C++调用C#代码)
- 托管的 Direct3D之 使用 Frame Hierarchy 创建动画(翻译)