惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
量子位
Google DeepMind News
Google DeepMind News
I
InfoQ
The GitHub Blog
The GitHub Blog
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
小众软件
小众软件
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
IT之家
IT之家

博客园 - 红色石头

删除表中多余的重复记录 c#里正则表达式的例子 水晶报表中动态显示图片 Javascript中定义类 - 红色石头 - 博客园 castle实例分析(二) castle实例分析(一) url传递中文的方法 - 红色石头 - 博客园 水晶报表中设定每页显示的行数 服务器控件Table的使用 asp.net2.0中关于ASP.NET 网站管理工具无法连接sql server 数据库的处理 转载一张有趣的图片 动态添加用户控件和服务器控件(二) 动态添加用户控件或服务器控件(一) XML格式的字符串和DataSet之间的相互转换 SQL Server2005关于web服务的配置 控制模版列的文本框在编辑时只读 控制模版列的文本框只能输入数字并且禁止粘贴 利用.net正则表达式化繁为简的一个实例 利用SqlServer2005的新增函数实现更高效的分页存储过程
在VS2005中用C#写存储过程
红色石头 · 2006-11-12 · via 博客园 - 红色石头

1.新建sql Server Project项目,并在项目中添加存储过程模版,此时自动引入System.Data.SqlServer命名空间,并创建一个static函数
2.在自动创建好的函数中添加如下代码,以下是返回SqlDataReader的实例。

 1using System;
 2using System.Data;
 3using System.Data.SqlClient;
 4using System.Data.SqlTypes;
 5using Microsoft.SqlServer.Server;
 6using System.Text;
 7
 8public partial class StoredProcedures
 9{
10    [Microsoft.SqlServer.Server.SqlProcedure]
11    public static void StoredProcedure1()
12    {
13        StringBuilder sqlSb = new StringBuilder();
14        string showFiled = "ZfId,ZfXm";
15        string fromTable = "Xf_ZfJbXx";
16        string conditionFiled = "ZfXb";
17        string valueString = "";
18
19        sqlSb.AppendFormat("select {0} from {1} where {2}='{3}'", showFiled, fromTable, conditionFiled, valueString);
20
21        using (SqlConnection cnn = new SqlConnection("Context Connection=true"))
22        {
23            using (SqlCommand sqlCmd = new SqlCommand())
24            {
25                cnn.Open();
26                sqlCmd.Connection = cnn;
27                sqlCmd.CommandText = sqlSb.ToString();
28                SqlDataReader sqlReader = sqlCmd.ExecuteReader();
29
30                SqlPipe sqlP = SqlContext.Pipe;
31                sqlP.Send(sqlReader);
32            }

33        }

34    }

35}
;
36
37


3.修改数据库的兼容级别:
打开查看SQL Server Management Studio,按照以下步骤操作:
鼠标右键选择使用的数据库,点击属性;选择-选项-兼容级别:SQL Server 2005(90).

4.如果CLR为关闭
则执行系统存储过程
sp_configure 'clr enabled','1'
        reconfigure

5.可以在查询分析器里运行此存储过程了。