如何创建存储过程 [英] how to create stored procedures

查看:64
本文介绍了如何创建存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,

我想用c#在asp.net中创建存储过程,以便我可以在我的项目中进一步使用它。我可以知道abt存储过程吗?在哪里创建?

hello sir,
i want to create stored procedures in asp.net using c# so that i can use it further in my project. can i know abt abt stored procedures. where to create it??

推荐答案

参考: Sql Server - 如何在Sql server中编写存储过程 [ ^ ]


在对象资源管理器中

在SQL中转到数据库

转到Programmability文件夹;转到存储过程 - >右键单击文件夹Stored Procedure

并单击New Stored Procedure。



您将获得存储过程的预定义变量和语法。

只需在BEGIN之后添加您的查询语句



一旦您获得了您创建的存储过程的成功消息。

转到程序并检查web.config文件中的用户名和SQL密码(如果已存在)

如果没有,请在web.config中输入用户名和密码

如果这对你来说很难。

只需在程序中自己给出连接字符串


In the object Explorer
Go to your database in SQL
Go to the folder Programmability; Go to Stored Procedure--> Right click on the folder Stored Procedure
and Click on New Stored Procedure.

You will get predefined Variable and Syntax for a Stored Procedure.
Just add your query statements after BEGIN

Once you get successful message for the Stored procedure you created.
Go to the program and check your web.config file for User name and Password for SQL if already exists
If not, give User name and password in web.config
If that is difficult for you.
Just give your connection string in the program it self

SqlConnection conn= new SqlConnection("Server=(local);DataBase=master;Integrated Security=SSPI");
                conn.Open();





并致电存储过程





and call the Stored procedure

SqlCommand cmd = new SqlCommand("StoreProcedureName",con);
cmd.CommandType=CommandType.StoreProcedure;
cmd.Parameters.AddWithValue("@value",txtValue.Text);
int rowAffected=cmd.ExecuteNonQuery();


相信我 Google [ ^ ]是你的朋友!用它。下次,请尊重规则 [ ^ ]!



本网站返回的2个结果:

CREATE PROCEDURE(Transact-SQL) [ ^ ]

如何使用参数创建SQL Server存储过程 [ ^ ]
Believe me Google[^] is your friend! Use it. Next time, please respect the rules[^]!

2 results returned by this site:
CREATE PROCEDURE (Transact-SQL)[^]
How to create a SQL Server stored procedure with parameters [^]


这篇关于如何创建存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆